Interview Prep/Helm/Templating: Go Templates & Sprig

How does whitespace control (`{{-` and `-}}`) work?

BeginnerConceptTemplating: Go Templates & Sprig
Answer

{{- trims all whitespace, including newlines, immediately before the action; -}} trims whitespace after it. Use them on control-flow lines (if, range, end, define) so they do not leave blank lines or break indentation.

metadata:
  labels:
    {{- include "shop.labels" . | nindent 4 }}

Over-trimming is a classic bug: {{- .Values.x -}} can glue two lines together and produce key: valueother: x. Check with helm template when in doubt.

All Helm questions Roadmap: Helm

More on Templating: Go Templates & Sprig