yaml-overlay-tool
yaml-overlay-tool copied to clipboard
Feature: Ability to lookup a value from an outside file or current yaml document and use it within a format marker
This is a decent use case where I'd like to look something up with a query within the same file or an external file, and plug it's value into somewhere within a yaml file (terrible statement). This may be something better suited for pure templating, but I think this could reduce some of the needs for templating in general. This needs to be thought out more, but I wanted to capture the idea.
Example:
File 1 - To look up a value I'd like to use in my overlays
---
some:
stuff:
here: cool
other:
stuff:
here:
a: apple
b: banana
Instructions file feature usage
---
# "path" key optional and would lookup a reference in the original yaml document?
references:
- name: ref1
path: ./file1.yaml
query: some.stuff.here
- name: ref2
path: ./file2.yaml
query: other.stuff.here[b]
yamlFiles:
- path: /file/to/modify.yaml
overlays:
- name: Use ref1
query: metadata.labels[app.kubernetes.io/name]
value: "%r{ref1}"
action: replace
- name: Use ref2
query: kind
value: "%r{ref2}"
action: replace
Expected Behavior:
- overlay 1 replaces the value of
metadata.labels['app.kubernetes.io/name']with the value ofcool - overlay 2 replaces the value of
kindwith the valuebanana
I'd like to use this to lookup and reference maps and arrays as well.
A use for this would be I deploy a bunch of stuff with Terraform and then spit it out in an orderly way with a template.
Then I want to populate a yaml based variables file with some of the info that I spit out from the terraform steps by looking up those references from the output to create a new yaml file that is properly configured for my new environment before further automation runs.
We do have the %v{r somefile.yaml}, but I want to look up (query) that file for the dynamic value's contents.