quote, default & indent
Three everyday functions: quote wraps strings, default supplies fallbacks, and indent/nindent handle YAML alignment.
{{ .Values.x | default "fallback" | quote }}
{{ toYaml .Values.y | nindent 4 }}A few functions appear in nearly every chart. Master these first.
quote
Wraps a value in double quotes. Essential for values that look like numbers or booleans but must be strings (like "true" or a version "1.20").
default
Supplies a fallback when a value is empty or unset: {{ .Values.tag | default "latest" }}.
indent and nindent
Correct indentation is critical in YAML. indent N adds N spaces to every line; nindent N does the same but first adds a newline β perfect for embedding a block under a key.
Example
spec:
containers:
- name: app
image: "nginx:{{ .Values.image.tag | default "latest" }}"
env:
- name: DEBUG
value: {{ .Values.debug | quote }}
resources:
{{- toYaml .Values.resources | nindent 8 }}When to use it
- A chart author wraps every string value from .Values in quote to prevent YAML parsing errors when operators pass values like 'true', '1', or 'null' that would otherwise be misinterpreted.
- A developer uses default to supply a fallback service port so the chart renders valid YAML even if the operator's values file omits the port field entirely.
- A template uses nindent 6 to embed a multi-line environment variable block inside a container spec with correct indentation, preventing YAML syntax errors.
More examples
quote prevents YAML type errors
Wrapping boolean and numeric-looking values in quote ensures Kubernetes receives a string rather than a boolean or integer.
env:
- name: FEATURE_FLAG
value: {{ .Values.featureFlag | quote }}
- name: TIMEOUT
value: {{ .Values.timeout | quote }}default supplies fallbacks
Uses default to guarantee sensible values even when the operator's values file does not define those keys.
spec:
replicas: {{ .Values.replicaCount | default 1 }}
template:
spec:
terminationGracePeriodSeconds: {{ .Values.gracePeriod | default 30 }}nindent for block alignment
Uses nindent with different levels to correctly align the label block and the env array within the Deployment spec.
spec:
template:
metadata:
labels:
{{- include "myapp.labels" . | nindent 8 }}
spec:
containers:
- name: app
env:
{{- toYaml .Values.env | nindent 12 }}
Discussion