Context
helmfile does not provide an explicit way to establish precedence of values under the values section. Thus, the following example is not a valid one:
values1.yamlfile:
key1: value1
values2.yaml.gotmplfile:
key2: {{ .Values.key1 }}
helmfile.yamlfile:
releases:
- name: release
chart: chart/name
values:
- values1.yaml
- values2.yaml.gotmpl
If you run, helmfile diff or helmfile sync, then helmfile will complain with the following error:
helmfile -f ./helmfile.yaml sync
Affected releases are:
release (chart/name) UPDATED
in ./helmfile.yaml:
failed processing release release:
failed to render values files "values2.yaml.gotmpl":
failed to render [values2.yaml.gotmpl], because of template:
stringTemplate:1:16: executing "stringTemplate" at <.Values.key1>:
map has no entry for key "key1"
Solution
A workaround is to leverage environments, which allows to customize the contents of helmfile.yaml and values files. By using golang templating, we can reference fields defined in the corresponding environment file in a particular values file.
default.yamlenvironment file:
key1: value1
values.yaml.gotmplfile:
key2: {{ .Values.key1 }}
helmfile.yamlfile:
environments:
default:
values:
- default.yaml
releases:
- name: release
chart: chart/name
values:
- values.yaml.gotmpl
With the new structure, running helmfile diff or hemlfile sync should work like a charm.