Interview Prep/Helm/Templating: Go Templates & Sprig

How do you work with lists and dicts in templates?

IntermediateConceptTemplating: Go Templates & Sprig
Answer

Sprig gives you list, append, first, last, has, uniq, compact, without, sortAlpha for lists, and dict, get, set, unset, hasKey, keys, values, pick, omit, merge, mergeOverwrite, deepCopy for dicts.

{{- $ctx := dict "root" $ "component" "api" "port" 3000 }}
{{- include "shop.deployment" $ctx }}
{{- if has "debug" .Values.api.flags }}...{{ end }}

set and unset mutate the dict in place and return it; use deepCopy before modifying .Values sub-maps, otherwise you change them for every later template.

All Helm questions Roadmap: Helm

More on Templating: Go Templates & Sprig