Interview Prep/Helm/Templating: Go Templates & Sprig

What is the difference between `merge` and `mergeOverwrite`?

AdvancedConceptTemplating: Go Templates & Sprig
Answer

Both deep-merge dicts into the first argument (mutating it). merge $dst $src keeps existing keys in $dst and only fills missing ones, so precedence goes to the left. mergeOverwrite $dst $src lets $src overwrite, so precedence goes to the right.

{{- $defaults := dict "replicas" 1 "port" 3000 }}
{{- $final := mergeOverwrite (deepCopy $defaults) .Values.api }}

Lists are replaced, not merged. Always deepCopy the destination when it is part of .Values, otherwise you mutate global state.

All Helm questions Roadmap: Helm

More on Templating: Go Templates & Sprig