Is there a way how I can import a .yaml
file in jsonnet?
I have found that jsonnet supports importing .json
and also has a native importstr()
function but looks like no support for .yaml
?
I would like to do:
local foo = import "foo.yaml";
local bar = foo.bar;
JSON is used to describe data literally. Jsonnet extends JSON. Jsonnet has relaxed syntax and comments to make it easier for humans to write. Jsonnet also adds constructs for generating, translating and refining data.
Jsonnet is a new domain specific configuration language from Google which allows you to define data templates. These data templates are transformed into JSON objects using Jsonnet library or command line tool. As a language, Jsonnet is extension of JSON - a valid JSON object is always valid Jsonnet template.
libsonnet is a library Jsonnet file, containing the base configuration for a service. Suppose that test_config. jsonnet is a test configuration file that is used to test base_config. jsonnet , and test_config. json is the expected JSON output from compiling test_config.
Not at the moment (May/2018), there's an open issue for it at https://github.com/google/jsonnet/issues/460, if you're working with Kubernetes manifests (importing + massaging w/jsonnet) you could use https://github.com/ksonnet/kubecfg which contains a superset of jsonnet, including std.parseYaml()
.
Update(2018-05-23): added
ksonnet
example
Using ksonnet
's embedded parseYaml
, at app folder:
$ cat assets/foo.yaml
foo: value1
bar: value2
$ cat components/cm.jsonnet
local env = std.extVar("__ksonnet/environments");
local params = std.extVar("__ksonnet/params").components.cm;
local k = import "k.libsonnet";
local configMap = k.core.v1.configMap;
local parseYaml = std.native("parseYaml");
configMap.new(params.name, params.data) {
data+: parseYaml(importstr "../assets/foo.yaml")[0] {
foo: "my own value",
},
}
$ ks show default
---
apiVersion: v1
data:
bar: value2
foo: my own value
kind: ConfigMap
metadata:
name: cm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With