Helmfile: Reading .Values in helmfile doesn't work when bases are specified

Created on 26 Mar 2021  路  2Comments  路  Source: roboll/helmfile

I have such helmfile.yaml

releases:
  - name: release
    namespace: namespace
    chart: repo/chart
    version: {{ .Values.chartVersion }}
    values:
      - "./{{ .Environment.Name }}/values.yaml"
environments:
  dev:
    values:
      - chartVersion: 0.3.0
bases:
  - ../helmfile.yaml

running helmfile --environment dev diff gives

in ./helmfile.yaml: error during helmfile.yaml.part.0 parsing: template: stringTemplate:5:23: executing "stringTemplate" at <.Values.chartVersion>: map has no entry for key "chartVersion"

If I use {{ readFile "../helmfile.yaml" }} instead of

bases:
  - ../helmfile.yaml

it works fine. The ../helmfile.yaml looks like this

repositories:
  - name: repo
    url: s3://some-s3-bucket/stable

helmDefaults:
  wait: true
  timeout: 300
  recreatePods: true

Most helpful comment

Yeah so this is kind of a chicken-and-egg problem. Helmfile needs to render helmfile.yaml template to load environment values but it needs values to render the template... For such cases, you could defer the template rendering to happen only after the values are loaded. Using ---, yours could probably be:

environments:
  dev:
    values:
      - chartVersion: 0.3.0

---

releases:
  - name: release
    namespace: namespace
    chart: repo/chart
    version: {{ .Values.chartVersion }}
    values:
      - "./{{ .Environment.Name }}/values.yaml"
bases:
  - ../helmfile.yaml

All 2 comments

The reason is that : helmfile.yaml is rendered before base layering is processed. Base layers are merged with helmfile to produce final values. If using bases, the environment values are not available at this first rendering of helmfile stage.

In your case, to use bases, you need to pass chartVersion as raw content in helmfile

version: '{{`{{ .Values.chartVersion }}`}}'
  • render helmfile
  • render base files
  • merge helmfile into base files and get envrionment values

Yeah so this is kind of a chicken-and-egg problem. Helmfile needs to render helmfile.yaml template to load environment values but it needs values to render the template... For such cases, you could defer the template rendering to happen only after the values are loaded. Using ---, yours could probably be:

environments:
  dev:
    values:
      - chartVersion: 0.3.0

---

releases:
  - name: release
    namespace: namespace
    chart: repo/chart
    version: {{ .Values.chartVersion }}
    values:
      - "./{{ .Environment.Name }}/values.yaml"
bases:
  - ../helmfile.yaml
Was this page helpful?
0 / 5 - 0 ratings

Related issues

RafalMaleska picture RafalMaleska  路  3Comments

mumoshu picture mumoshu  路  4Comments

cilerler picture cilerler  路  4Comments

michaelpporter picture michaelpporter  路  3Comments

maver1ck picture maver1ck  路  3Comments