Conditional
Choose between values inside an expression: defaults for empty values, the first non-empty of several, and ternaries, so a template does not need an if block for a one-line choice.
Reference
| Function | Description |
|---|---|
boolDefault | Returns the field’s boolean value if it is a bool, otherwise returns def. |
boolTernary | Is like ternary but requires a strict bool argument. |
coalesce | Returns the first non-empty value from a variadic list. |
default | Returns val if non-empty, otherwise returns def. |
empty | Returns true when the value is empty (nil, "", 0, false, empty slice, empty map, or "<no value>"). |
eqTernary | Returns trueVal when val equals target (string comparison), falseVal otherwise. |
notEmpty | Returns true when the value is non-empty. |
ternary | Returns trueVal when condition is truthy, falseVal otherwise. |
Functions
boolDefault
boolDefault returns the field’s boolean value if it is a bool, otherwise returns def. Useful when a boolean field may be absent (nil).
{{ boolDefault .spec.suspend false }} → false
boolTernary
boolTernary is like ternary but requires a strict bool argument. Use this when the field is declared as a boolean in the CRD schema — it avoids the truthiness ambiguity of ternary for values like 0, "", or [].
{{ boolTernary .spec.debug "debug" "info" }} → "debug"
coalesce
coalesce returns the first non-empty value from a variadic list. Useful when a field can come from multiple sources with a final fallback.
{{ coalesce .spec.sidecarImage .spec.defaultSidecarImage "envoyproxy/envoy:v1.30" }} → "envoyproxy/envoy:v1.30"
default
default returns val if non-empty, otherwise returns def. “Empty” means nil, "", 0, false, empty slice, or empty map.
{{ default "info" .spec.logLevel }} → "info"
{{ .spec.logLevel | default "info" }} → "info"
empty
empty returns true when the value is empty (nil, "", 0, false, empty slice, empty map, or "<no value>").
{{ empty .spec.logLevel }} → true
eqTernary
eqTernary returns trueVal when val equals target (string comparison), falseVal otherwise. Shorthand for the boolTernary (eq val target) trueVal falseVal pattern — useful when branching on a string field value such as a status string, a mode flag, or a cross-CRD found result.
{{ eqTernary .spec.mode "production" "strict" "permissive" }} → "strict"
notEmpty
notEmpty returns true when the value is non-empty. The inverse of empty.
{{ notEmpty .spec.mode }} → true
ternary
ternary returns trueVal when condition is truthy, falseVal otherwise. Condition truthiness follows Go rules: non-empty string, non-zero number, non-empty slice/map, true bool.
{{ ternary .spec.debug "debug" "info" }} → "debug"