Interview Prep/Helm/Templating: Go Templates & Sprig

How does `with` work, and what is its common pitfall?

IntermediateConceptTemplating: Go Templates & Sprig
Answer

with sets . to the value if it is non-empty and skips the block otherwise. It is ideal for optional blocks:

{{- with .Values.nodeSelector }}
nodeSelector:
  {{- toYaml . | nindent 8 }}
{{- end }}

Pitfall: inside the block you cannot reach .Values or .Release through .; use $. Also, a value of 0 or false skips the block.

All Helm questions Roadmap: Helm

More on Templating: Go Templates & Sprig