Interview Prep/Helm/Templating: Go Templates & Sprig

What does `toYaml` do and when do you use it?

BeginnerConceptTemplating: Go Templates & Sprig
Answer

toYaml serializes a value (map, list, scalar) as YAML text. It is the standard way to pass through whole blocks the chart does not want to model field by field: resources, securityContext, affinity, tolerations, nodeSelector, extra volumes.

securityContext:
  {{- toYaml .Values.api.securityContext | nindent 12 }}

It also handles quoting of special strings correctly, unlike hand-written templates.

All Helm questions Roadmap: Helm

More on Templating: Go Templates & Sprig