I'm trying to come up with a setup for a customer that will produce values.yaml
for a helm
chart using consul-template
.
The "brain" is that there are defaults per environment, defaults per service, and concrete values for a specific service in a specific environment, and all these defaults should be merged.
The project I inherited uses git2consul
and expresses every key in the tree in it's own file, so that trees are explode
ed into toYAML
as follows:
{{- $service := env "SERVICE_NAME" -}}
{{- $env := env "ENV" -}}
{{ (tree (print "_all-envs/_all-svcs" ) | explode)
| mergeMap (tree (print "_all-envs/" $service ) | explode)
| mergeMap (tree (print $env "/_all-svcs" ) | explode)
| mergeMap (tree (print $env "/" $service ) | explode)
| toYAML }}
But then, I get numbers and booleans represented as explicit strings, because toYAML
is not type aware, and spits everything as a string - and if it's not a natural string toYAML
forces it to be an explicit string.
So I started to fiddle with hacking around toYAML to format things back to num/bool and this feels like not the right direction because sometimes true
needs to be a boolean and in other cases - the chart wants it to yet be a string (i.e "boolean"
).
So I'm trying to come with an alternative, where I try to keep entire YAML docs in keys (instead of in trees), and since YAML is type-aware - I should expect the types to be preserved.
However, I cannot find a way how I can merge yaml documents parsed from keys. My current thought was something in the spirit of:
{{ key "_all-envs/_all-svcs" | parseYAML
| mergeMap (print "_all-envs/" $service | key | parseYAML ))
| mergeMap (print $env "/_all-svcs" | key | parseYAML ))
| mergeMap (print $env "/" $service | key | parseYAML ))
| toYAML }}
However, this fails with:
wrong type for value; expected map[string]interface {}; got map[interface {}]interface {}
How should I solve this?
If it cannot be done with consul-template
, I'll need to develop an inhouse code for that, that gets a list of keys that hold docs and deep-merges them in the right order.
However, the customer would like to avoid that and stick to public tools...