Values precedence in helmfile

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.yaml file:
key1: value1
  • values2.yaml.gotmpl file:
key2: 
  • helmfile.yaml file:
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.yaml environment file:
key1: value1
  • values.yaml.gotmpl file:
key2: 
  • helmfile.yaml file:
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.

References #

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.