bkl is a templating configuration language without the templates. It's designed to be simple to read and write with obvious behavior.
Write your configuration in your favorite format: JSON, YAML, or TOML. Layer configurations on top of each other, even from different file formats. Use filenames to define the inheritance. Have as many layers as you like. bkl merges your layers together with sane default behavior that you can override. Export your results in any supported format for human or machine consumption. Use the CLI directly or in scripts or automate with the library.
Inheritance is determined using filenames by default. After stripping the extension, the remaining filename is split on . and treated as an inheritance hierarchy (e.g. a.b.c.yaml inherits from a.b.<ext> inherits from a.<ext>). Parent layers may have any supported file extension.
$parent: a.b# inherits from a.b., from a.
bkl will check for all supported endings of a manually-specified parent file and will still evaluate layers under the parent in the normal order.
$parent:- a- b
$parent: a.*
$parent supports lists and wildcards for multiple inheritance. Wildcard * matches one segment only: a.* matches a.b.yaml but not a.b.c.yaml.
Streams contain multiple documents in one file. YAML uses --- delimiters. JSON formats use newlines (see JSON Lines).
By default, child documents apply to all parent documents. Use $match to target specific documents.
a: 1---b: 2
+
c: 3
=
a: 1c: 3---b: 2c: 3
a: 1---b: 2
+
$match:b: 2c: 3
=
a: 1---b: 2c: 3
The supplied pattern can match multiple documents and the updates will be applied to all of them. $match: {} matches any documents with a map as their root element, regardless of parent.
a: 1---b: 2---a: 1
+
$match:a: 1c: 3
=
a: 1c: 3---b: 2---a: 1c: 3
$invert: true inside a $match block inverts the match, causing it to apply to any documents that do not contain the match criteria.
a: 1---b: 2
+
$match:a: 1$invert: truec: 3
=
a: 1---b: 2c: 3
$match: null forces the updates to apply to a new document.
Maps are merged by default. Use $replace: true to replace the entire map or $delete to remove specific keys.
a: 1
+
b: 2
=
a: 1b: 2
a: 1
+
b: 2$replace: true
=
b: 2
a: 1b: 2
+
c: 3b: $delete
=
a: 1c: 3
bkl returns an error if you use $delete, $replace: true, or a key: value pair when they don't override a value from a lower layer. This helps keep upper layers minimal.
$repeat: at the top level of a document causes the document to be duplicated the given number of times. Within the document, $repeat can be used to reference the zero-based repeat index.
a: foob: $repeat$repeat: 2
=
a: foob: 0---a: foob: 1
$repeat: can also contain a map of named repeat iterators to repeat count. The result is the cartesian product (all combinations) of repeat values.
bklb is a wrapper for CLI programs that take configuration files as commandline arguments but do not support bkl format. It transparently merges layers, translates formats, writes to temporary files, alters the commandline arguments, then execs the wrapped program.
$ ln-s~/go/bin/bklb~/go/bin/catb# catb could be, e.g. kubectlb$ catservice.yamladdr: 127.0.0.1name: myServiceport: 8080$ catservice.test.tomlport = 8081$ catbservice.test.tomladdr = "127.0.0.1"name = "myService"port = 8081$ cat service.test.yamlservice.test.jsoncat:service.test.yaml:Nosuchfileordirectorycat:service.test.json:Nosuchfileordirectory$ catbservice.test.yamladdr: 127.0.0.1name: myServiceport: 8081$ catb service.test.json
{"addr":"127.0.0.1","name":"myService","port":8081}
Note that the files mentioned don't have to exist; bklb will search for files with the same root name but different extensions, then merge layers and translate into the specified format.
bklb takes the name of the program it wraps from its own filename, hence the ln -s symlink creation in the example above. It trims at most one b from the end of its name before searching for the wrapped program so they can coexist in your PATH.
bkld (d for "diff") generates the minimal intermediate layer needed to create the target output from the base layer. Along with bkli, it automates splitting existing configurations into layers.
Use --selector to limit processing to documents matching a specific path.
bkli (i for "intersect") generates the maximal base layer that the specified targets have in common. Along with bkld, it automates splitting existing configurations into layers.
Fields that exist in all inputs with the same value are included in the result. Fields with different values are omitted.
Use --selector to limit processing to documents matching a specific path.
bklc (c for "compare") compares two bkl files and shows colorized text differences between their evaluated outputs. Use --color to enable colored output. Use --sort to order documents by a specific path before comparison.
kubectl bkl is a kubectl plugin that wraps all the normal kubectl commands by evaluating any input files as bkl layers and passing the output to kubectl.
# deploy.dev.yaml and deploy.yaml are bkl layer files$ kubectlbklapply-fdeploy.dev.yamldeployment.apps/deploy-devunchanged