kubernetes-helmhelmfile

Using nested values defined in environment


I have the following helmfile

releases:
  - name: whoami-mn
    namespace: whoami-mn-{{ .Environment.Name }}
    chart: tons/whoami-mn
    version: {{ .Values.chartVersions.whoami }}
    installed: {{ .Values.installed }}
    values:
      - env/{{ .Environment.Name }}-values.yaml

environments:
  dev:
    values:
      - installed: true
      - chartVersions:
          whoami: 0.3.0
          otherApp: 0.2.0
  prod:
    values:
      - installed: true
      - chartVersions:
          whoami: 0.2.0
          otherApp: 0.1.0

But when running helmfile -e dev template I get the following error in ./helmfile.yaml: error during helmfile.yaml.part.0 parsing: template: stringTemplate:5:23: executing "stringTemplate" at <.Values.chartVersions.whoami>: map has no entry for key "chartVersions"

I can do something like the following

environments:
  dev:
    values:
      - installed: true
      - chartVersionWhoami: 0.3.0

That works but I'd prefer having all chart version grouped under a parent key. Any suggestions about how to get the former working?

UPDATE: The following works

...
version: {{ (index .Values "chartVersions").whoamiMn }}
...

With the environment defined like the following

environments:
  dev:
    values:
      - installed: true
      - chartVersions:
          whoamiMn: 0.3.0

But I really feel like my first attempt should work as well!


Solution

  • After experimenting and discussing further here. I figured out that I can fix this issue by simply listing my environments before my releases. In my pedantic point of view I'd appreciate having my releases listed first but it works.