helmfile: Unexpected rendering issue for v1 mode

Operating system

Ubuntu 20.04.4 LTS

Helmfile Version

0.152.0

Helm Version

3.11.2

Bug description

I’ve started to look into our helmfile v1 mode and bumped into an issue.

In the attached helmfile.yaml.gotmpl the $configDir variable is added as a value, and within same yaml document the environments (attached envs.yaml) section is loaded, which uses the configDir previously added .Values. However, in v1 mode this fails with:

in ./helmfile.yaml.gotmpl: error during helmfile.yaml.gotmpl.part.0 parsing: template: stringTemplate:9:6: executing "stringTemplate" at <tpl (readFile $envFile) .>: error calling tpl: template: stringTemplate:4:18: executing "stringTemplate" at <.Values.configDir>: map has no entry for key "configDir

Without v1 mode it works fine, i.e. configDir in .Values is instantly exposed to the envs.yaml rendering, even if adding of configDir to .Values is done within same yaml document as the envs.yaml rendering.

Using attached files this can be reproduced by:

export HELMFILE_V1MODE=true && helmfile -e prod template

It is working with:

export HELMFILE_V1MODE=false && helmfile -e prod template

Example helmfile.yaml

helmfile.yaml.gotmpl :

{{ $configDir := default (env "CONFIG_DIR") | default "config" }}
values:
- configDir: {{ $configDir }}
{{ tpl (readFile (printf "%s/envs.yaml" $configDir)) . }}
---
repositories:
- name: incubator
  url: https://charts.helm.sh/incubator
---
releases:
- name: service-a
  chart: incubator/raw
  values:
  - resources:
    - apiVersion: v1
      kind: ConfigMap
      metadata:
        name: raw1
        namespace: default
      data:
        foo: {{ .Values | get "some-random-key" "" }}

envs.yaml :

environments:
  prod:
    values:
      - {{ .Values.configDir }}/envs/prod/values.yaml

config/envs/prod/values.yaml :

some-random-key: with-some-random-value

Error message you’ve seen (if any)

in ./helmfile.yaml.gotmpl: error during helmfile.yaml.gotmpl.part.0 parsing: template: stringTemplate:9:6: executing "stringTemplate" at <tpl (readFile $envFile) .>: error calling tpl: template: stringTemplate:4:18: executing "stringTemplate" at <.Values.configDir>: map has no entry for key "configDir

Steps to reproduce

See bug description

Working Helmfile Version

N/A

Relevant discussion

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 26 (15 by maintainers)

Commits related to this issue

Most upvoted comments

I agree this could be considered a bug, that the crucial part is that the specified environment is defined at some point, not as today that it has to be defined in the first yaml document.

@yxxhero @mumoshu - relabel this as a bug?

my example works fine. you got me. @mumoshu