yaml-overlay-tool
yaml-overlay-tool copied to clipboard
Feature: Ability to take a single YAML document from a YAML file, and loop (via templating) to create additional YAML documents from it
As a user, I have a collection of iterable values, a single document YAML file, and I would like to iterate over the initial YAML document (treated as a starting point/template) to generate 1 or many new YAML documents to be output to the YAML file from the iterable values.
This could either be a new action
or simply a method to use a source document within a YAML file.
This is an idea I have floating around on how to potentially solve this particular issue, and is open to feedback and discussion:
Given values passed in with either the -d or -v parameters:
# values can be used for templating or iterable document creation
some:
things:
- name: thing1
contents:
- stuff
meta:
annotations:
some: thing
- name: thing2
contents:
- moreStuff
- andEvenMoreStuff
meta:
annotations:
another: thing
Given a yaml file (/my/template/file.yaml):
# scaffolded yaml file for example, but could include real data to start, which would allow for yot actions to do more here
metadata:
annotations: {}
name: ""
contents: []
Given an instruction file API schema:
# In this example, only the 'value' field can be populated.
yamlFiles:
- name: Generate a new yaml file with multiple documents using another file as a base template
path: /my/template/file.yaml
withIterable: some.things
outputPath: newThings.yaml
overlays:
- name: populate annotations
query: metadata.annotations
value: meta.annotations
action: replace
- name: populate name
query: metadata.name
value: name
action: replace
- name: populate contents
query: contents
value: contents
action: replace
This would generate "newThings.yaml" with multiple yaml documents as such:
metadata:
annotations:
some: thing
name: thing1
contents:
- stuff
---
metadata:
annotations:
another: thing
name: thing2
contents:
- moreStuff
- andEvenMoreStuff
Real-world example for this use-case is creating many storage-classes in a kubernetes cluster from a collection of iterable values. This is one example where templating yaml files works well, but this would close the gap.
FWIW the storage class use case totally makes sense to me. Not everyone will need this feature... but for those that do it could prevent them having to use another tool just to fill this gap.