I have a values.yaml that has the following:
abc:
env:
- name: name01
value: value01
- name: name02
value: value02
and I have another values file values-dev.yaml that I add when installing using -f and it has:
abc:
env:
- name: name03
value: value03
and using range I list them in my template. My hope was that the list would become like this after both files are applied:
abc:
env:
- name: name01
value: value01
- name: name02
value: value02
- name: name03
value: value03
but the values-dev.yaml values will override the one in the values.yaml and it becomes:
abc:
env:
- name: name03
value: value03
How can I achieve merging these 2 lists with the same field names from different values files?
Yes, it's possible to have multiple values files with Helm. Just use the --values flag (or -f ). You can also pass in a single value using --set . --set (and its variants --set-string and --set-file): Specify overrides on the command line.
You can use a --values flag in your Helm commands to override the values in a chart and pass in a new file. Specify the name of the new file after the --values flag in the Helm command. Example: helm upgrade --install <service> -f values.
To perform a helm release upgrade using the CLI, run the following command provided: helm upgrade <release name> <chart directory> -f my-values. yaml using the configuration specified in the customized values. yaml file. After a successful upgrade, the helm will return the following message.
The tpl function allows developers to evaluate strings as templates inside a template. This is useful to pass a template string as a value to a chart or render external configuration files. Syntax: {{ tpl TEMPLATE_STRING VALUES }}
Short answer is, you can not merge lists
.
In your case abc.env
is the key
and the value
is a list. Let me re-write your first values file in an equivalent notation and it will be more clear:
abc:
env: [{name: name01, value: value01}, {name: name02, value: value02}]
So Helm is doing what is expected, overriding the key abc.env
with the last provided one.
Solution is re-structuring your values files, like this:
abc:
env:
name01: value01
name02: value02
This way, you can merge and override your values files as desired. This way, it's also much easy to override a single value with command line flag, for example:
--set abc.env.name01=different
With some Helm magic, it's easy to pass those values as environment variables to your pods:
...
containers:
- name: abc
image: abc
env:
{{- range $key, $value := .Values.abc.env }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With