helm: Cannot access $ in template
Output of helm version
: v3.12.0
Output of kubectl version
: none
Cloud Provider/Platform (AKS, GKE, Minikube etc.): mac
mininal reproducable example:
./templates/foo/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: qwe
{{- include "hello.configmap" .Values.qq }}
./templates/_helper.tpl
{{- define "hello.configmap" -}}
data:
foo: |
{{ .bar }}
{{$.Values.foo}}
{{- end }}
values.yaml
foo: "adasds"
qq:
bar: "qqqq"
helm template .
outputs:
Error: template: example/templates/foo/configmap.yaml:6:4: executing "example/templates/foo/configmap.yaml" at <include "hello.configmap" .Values.qq>: error calling include: template: example/templates/_helpers.tpl:8:7: executing "hello.configmap" at <$.Values.foo>: nil pointer evaluating interface {}.foo
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 22 (11 by maintainers)
Not a bug.
The documentation briefly mentions:
https://helm.sh/docs/chart_template_guide/named_templates/#setting-the-scope-of-a-template
Often I build my own dicts to pass to named templates to have the data available:
@PavanButke this is not a bug. thanks.
Honestly you’re being pedantic and veering off on some academic school lesson I can’t say anyone is massively interested in.
It’s very clear (now) how
$
works. Again, this is a Helm community, not Go developer community; although I appreciate the$$
Go-developer effort may seem like/be more effort than it’s worth the possible Helm-templater UX/valueRight. That quote comes from https://helm.sh/docs/chart_template_guide/variables/ which is about template variables. Named templates are special in that their root context is whatever you pass to them in your include statement.
@caibirdme the key issue is
$
indefine
. you can test it locally.@caibirdme you should know the scope of
$
indefine
.For context:
https://pkg.go.dev/text/template#hdr-Variables