You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When tpl is used like shown above anywhere inside the range loop, it throws an error: $ helm template . --values values.yaml Error: template: tt/templates/service.yaml:4:8: executing "tt/templates/service.yaml" at <tpl $.Values.myApp.appName .>: error calling tpl: error during tpl function execution for "{{ $.Values.mA }}-is-here": template: gotpl:1:4: executing "gotpl" at <$.Values.mA>: nil pointer evaluating interface {}.mA
The text was updated successfully, but these errors were encountered:
MilanMasek
changed the title
tpl trick https://helm.sh/docs/howto/charts_tips_and_tricks/#using-the-tpl-function throws an error when used inside the range function
tpl trick https://helm.sh/docs/howto/charts_tips_and_tricks/#using-the-tpl-function throws an error when used inside the range loop
Apr 12, 2024
@MilanMasek When you move it inside the range, the scope changes. Since you want to stay at the top, or "root" scope, replace the . with a $ as shown below:
Output of
helm version
:version.BuildInfo{Version:"v3.14.3", GitCommit:"f03cc04caaa8f6d7c3e67cf918929150cf6f3f12", GitTreeState:"clean", GoVersion:"go1.21.7"}
Following example works. When the first line of template/service.yaml is moved inside the range loop, it throws an error.
`
$ cat values.yaml
mA: "my-awesome-app"
myApp:
appName: "{{ $.Values.mA }}-is-here"
replicas: 3
ports:
- 80
- 443
services:
- name: "web"
port: 80
- name: "api"
port: 8080
$ cat templates/service.yaml
app: {{ tpl $.Values.myApp.appName . }}
{{- range .Values.myApp.services }}
apiVersion: v1
kind: Service
metadata:
name: {{ .name }}-svc
spec:
ports:
- port: {{ .port }}
name: http
selector:
{{- end }}
`
When tpl is used like shown above anywhere inside the range loop, it throws an error:
$ helm template . --values values.yaml Error: template: tt/templates/service.yaml:4:8: executing "tt/templates/service.yaml" at <tpl $.Values.myApp.appName .>: error calling tpl: error during tpl function execution for "{{ $.Values.mA }}-is-here": template: gotpl:1:4: executing "gotpl" at <$.Values.mA>: nil pointer evaluating interface {}.mA
The text was updated successfully, but these errors were encountered: