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
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 }}`}}'
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
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: