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
- feat: `get` and `getOrNil` template funcs to allow defaulting in templates Ref #357 — committed to mumoshu/helmfile by mumoshu 6 years ago
- feat: `get` and `getOrNil` template funcs to allow defaulting in templates Ref #357 — committed to mumoshu/helmfile by mumoshu 6 years ago
- feat: `get` and `getOrNil` template funcs to allow defaulting in templates Ref #357 — committed to mumoshu/helmfile by mumoshu 6 years ago
- feat: `get` and `getOrNil` template funcs to allow defaulting in templates (#370) * feat: `get` and `getOrNil` template funcs to allow defaulting in templates Ref #357 * Add docs about missing ... — committed to roboll/helmfile by mumoshu 6 years ago
- feat: Enhanced `get` template function `get` is now able to take one more optional argument, that is used as the default value when the value for the key does not exist. Resolves #465 Fixes #427 Fix... — committed to mumoshu/helmfile by mumoshu 5 years ago
- feat: Enhanced `get` template function `get` is now able to take one more optional argument, that is used as the default value when the value for the key does not exist. Resolves #465 Fixes #427 Fix... — committed to mumoshu/helmfile by mumoshu 5 years ago
- feat: Enhanced `get` template function (#513) `get` is now able to take one more optional argument, that is used as the default value when the value for the key does not exist. Resolves #465 Fixe... — committed to roboll/helmfile by mumoshu 5 years ago
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.Environmenttoo.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
Where is
Environment.Values.eventApi.replicasis not set it would return a 1.@apetheriotis @sstarcher I’m going to deprecate
getOrDefaultand enhancegetas described in #465Thank 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
defaultValueIfKeyAbsentor too big ?Thank you both for the clarification and no worries about the docs.
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: 1in 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 valuereplicas:just once (only in prod.yaml).