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.
More on Templating: Go Templates & Sprig
What template language does Helm use?BeginnerWhat does the dot (`.`) mean in a Helm template?BeginnerWhat is `$` and when do you need it?IntermediateHow does whitespace control (`{{-` and `-}}`) work?BeginnerHow do `if`, `else if` and `else` evaluate truthiness?BeginnerWhat do `and`, `or`, `not`, `eq`, `ne`, `lt`, `gt` look like in Helm?Beginner