0Pricing
Helm Academy · Lesson

Deep Merge with mergeOverwrite and dict

Composing structured values programmatically.

Deep Merge with mergeOverwrite and dict is a free Helm Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Helm Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Building Maps in Templates

Sometimes you need to assemble a map inside a template. The dict function creates one from alternating key and value pairs.

{{ $cfg := dict "level" "info" "json" true }}

Why Combine Maps

You often have chart defaults plus user overrides, and you want a single combined map. That is exactly what a merge produces.

Shallow merge

The merge function copies keys from source maps into a destination, but it keeps the destination value whenever a key already exists.

{{ $out := merge $user $defaults }}

merge Favors the Destination

With merge, the first argument wins on any clashing key, so it is ideal when user input should override your defaults.

Enter mergeOverwrite

The mergeOverwrite function does the opposite: later source maps overwrite the destination, layering values on top.

{{ $out := mergeOverwrite $defaults $user }}

Deep, Not Shallow

Both helpers merge recursively: nested maps are combined key by key rather than the whole subtree being replaced wholesale.

Mutation Warning

Careful: merge and mergeOverwrite mutate their first argument in place. Pass a fresh dict if you must keep the original intact.

{{ $base := dict }}{{ $r := mergeOverwrite $base .Values.extra }}

A Layered Defaults Pattern

A common pattern is to start from a defaults dict, then layer user values on top so unset keys fall back safely.

{{ $merged := mergeOverwrite (dict "port" 80) .Values.service }}

Reading Merged Values

Once merged, you treat the result like any map and pull keys out with dot or the index function as usual.

{{ $merged.port }}

Serialize the Result

To emit a merged structure as YAML, pipe it through toYaml and nindent so the block lands at the right indentation.

{{ toYaml $merged | nindent 4 }}

Picking Out One Key

When a key name is dynamic or holds odd characters, reach into the map with the index function instead of dot access.

{{ index $merged "log-level" }}

Quick Check

Quick check on overwrite direction.

Recap

You met dict to build maps, merge to keep destination keys, and mergeOverwrite to let later values win, all merging deeply. 🎉

Frequently asked questions

Is the “Deep Merge with mergeOverwrite and dict” lesson free?

Yes — the full text of “Deep Merge with mergeOverwrite and dict” is free to read here on the web, and the Helm Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Helm Academy course, upgrade to CoddyKit PRO.

What will I learn in “Deep Merge with mergeOverwrite and dict”?

Composing structured values programmatically. You practise Helm Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Helm Academy?

No prior experience is required. Helm Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Deep Merge with mergeOverwrite and dict” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Helm Academy lesson?

Yes. Every Helm Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Deep Merge with mergeOverwrite and dict
  2. tpl: Rendering Strings from Values
  3. Looping Files with range Over .Files.Glob
  4. fail and Custom Validation Guards
← Back to Helm Academy