Open jandubois opened 4 years ago
Because this is so finicky, I'd like to add to the acceptance criteria:
I am looking also forward to this tool, to merge values.yaml that would be used for testing harnesses.
Example: merge-yaml kubecf-diego-values.yaml kubecf-ingress-values.yaml kubecf-develop-values.yaml
Where:
kubecf-diego-values.yaml
example production values for a diego deploymentkubecf-ingress-values.yaml
example production values for a kubecf deployment with ingresskubecf-develop-values.yaml
develop values, enabling testsuites and configuring them (cats, gingko nodes, etc), changing docker_registry, etc.Also, I'm looking forward to this tool, to merge values.yaml for k8s providers in catapult.
Example: merge-yaml default-catapult-values.yaml your-catapult-caasp-ecp-values.yaml
(this usecase is simpler as it could be done without comments)
Is your feature request related to a problem? Please describe.
We want to be able to have separate
values.yaml
files for each component in themixins/
directory. Unlike theconfig/*.yaml
files, thevalues.yaml
files cannot be mixed in a single target directory, where they all use separate names; we need a single finalvalues.yaml
file for the helm chart. Obviously comments in both the mainvalues.yaml
file and in the ones to be merged in should be retained.Another use case is updating YAML files via CI, like bumping the version of the Eirini image in
mixins/eirini/config/eirini.yaml
#841Describe the solution you'd like
I would like to see a tool in kubecf-tools that merges multiple YAML files, e.g.
There may be existing code in create_sample_value.rb that can be reused for this project.
To have predictable merging semantics I think it is sensible to expect all input YAML files to be well-formatted, and also have all keys in sorted sequence. Additional constraints may become obvious once implementation starts.
Each comment block belongs to the key below it.
Instead of writing a spec I'll just try to give an example with
file1.yaml
:and
file2.yaml
:Merging:
Running
merge-yaml
on a single file will effectivelylint
the file (indentation is proper, keys are sorted). If it doesn't throw an error, it will just copy the input file to STDOUT.Optional/special rules:
A comment block at the top of the file, until the first empty line, is a file level comment and does not belong to any key (could be implemented with a special empty key that will sort to the top, but the key is suppressed on output.
Comments starting with
##
(or some other sequence) are internal and will be omitted from the output file.Describe alternatives you've considered
I've tried to use ruamel.yaml to merge YAML files, but the library is buggy. Sometimes the indentation was messed up, sometimes comments appeared in the wrong places, and I think once even the data itself was mangled.