Interview Prep/Helm/Templating: Go Templates & Sprig

How do you loop over a list and over a map with `range`?

IntermediateConceptTemplating: Go Templates & Sprig
Answer
# list
{{- range $i, $host := .Values.ingress.hosts }}
- host: {{ $host | quote }}   # $i is the index
{{- end }}

# map (keys iterate in sorted order)
env:
{{- range $key, $val := .Values.api.env }}
  - name: {{ $key }}
    value: {{ $val | quote }}
{{- end }}

Maps iterate in sorted key order, so output is deterministic. Generate a numeric sequence with until 3 or untilStep 0 10 2.

All Helm questions Roadmap: Helm

More on Templating: Go Templates & Sprig