helmfile: Go templates `default` functionality is broken after version 0.33.0

The following example (it’s provided in the helmfile readme) works on version 0.33 but on version 0.34 and onwards:

helmfile.yaml

environments:
  production:
    values:
    - production.yaml

releases:
- name: myapp
  values:
  - values.yaml.gotmpl

production.yaml

domain: prod.example.com
releaseName: prod
values.yaml.gotmpl

domain: {{ .Environment.Values.domain | default "dev.example.com" }}

The above setup fails on version 0.34 and onwards with:

 map has no entry for key "domain"

when the domain value is missing from the environment file production.yaml

Probably the functionality of go templates is not the expected one when the key is missing from the values file.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 22 (11 by maintainers)

Commits related to this issue

Most upvoted comments

How about {{ .Environment.Values | getOrNil "eventApi.replicas" | default 1 }}? A side-effect of thjis is that it also allows using hyphens in keys which I saw in another issue, and allows digging things other than .Environment too.

Either that or something that works differently then default, which would allow us to do the lookup like exists, but to catch the error.

something like

{{ defaultValue ".Environment.Values.eventApi.replicas" 1 }}

Where is Environment.Values.eventApi.replicas is not set it would return a 1.

@apetheriotis @sstarcher I’m going to deprecate getOrDefault and enhance get as described in #465

Thank you for fixing that !

Personally I don’t prefer having another flag. I’d say as it is now it’s good enough 👍

I like it

onNull ?

{{ onNull ".Environment.Values.eventApi.replicas" 1 }} {{ defaultValue ".Environment.Values.eventApi.replicas" 1 }} {{ defaultValueIfKeyAbsent ".Environment.Values.eventApi.replicas" 1 }}

maybe defaultValueIfKeyAbsent or too big ?

Thank you both for the clarification and no worries about the docs.

You should explicitly set the default value, in this case “dev.example.com”, explicitly in your production.yaml.

I think following the above approach results in having a lot of duplicated values . For example in our case with 30 apps and 6 environments we would need to copy the value replicas: 1 in 5 different files and only change it in one file (prod.yaml) replicas:2. Instead if we could default it, we would have to declare the value replicas: just once (only in prod.yaml).