Helm template context

Inside a range loop in Helm template, the context refers to the current item in the loop iteration. This means that when you use . inside a range loop, you’re accessing the current item in the loop.

$. refers to the top-level context that was passed into the template, and you can use it to access properties that are outside of the current range loop.

If you want to access the .Values variable inside a named template included inside a range loop, you can pass it as an argument to the template.

{{- define “my-template” }}
{{- $myVar := $.Values.myVar }}
{{- printf “myVar: %s” $myVar }}
{{- end }}

{{- range .items }}
{{- include “my-template” . (dict “Values” $.Values) }}
{{- end }}

From ChatGPT and validated/edited by myself

Leave a comment