Interview Prep/Helm/Templating: Go Templates & Sprig

What is `$` and when do you need it?

IntermediateConceptTemplating: Go Templates & Sprig
Answer

$ is always bound to the root context passed to the template, no matter how deeply with/range changed .. You need it to reach .Release or .Values from inside a loop:

{{- range .Values.api.extraEnv }}
- name: {{ .name }}
  value: {{ .value | quote }}
- name: {{ .name }}_RELEASE
  value: {{ $.Release.Name }}
{{- end }}

Writing .Release.Name inside the range fails with can't evaluate field Release in type map[string]interface {}.

All Helm questions Roadmap: Helm

More on Templating: Go Templates & Sprig