Conditional Notes

2 min read

Value selection and truthiness helpers. Replace {{ if }}...{{ else }}...{{ end }} blocks with inline expressions.

Reference

NoteSignatureReturns
ternarycond, trueVal, falseVal interface{}trueVal if cond is truthy, else falseVal
boolTernarycond bool, trueVal, falseVal interface{}trueVal if cond is true
boolDefaultv interface{}, def boolbool — use when field may be absent
coalescevals ...interface{}first non-empty value
defaultval, def interface{}val if non-empty, else def
emptyv interface{}bool — true for nil, "", 0, false, empty slice/map
notEmptyv interface{}bool — inverse of empty

ternary vs boolTernary

ternary uses Orkestra’s truthiness rules — a non-empty string, non-zero number, or non-nil map is truthy. Use it for general conditions.

boolTernary requires a strict Go bool. Use it when the field is a typed boolean (e.g. spec.suspend, spec.enabled) to avoid truthiness surprises with string representations of "false".

# General condition
value: "{{ ternary .spec.debug \"debug\" \"info\" }}"

# Typed bool field — spec.suspend is a bool, not a string
value: "{{ boolTernary .spec.suspend \"Suspended\" \"Active\" }}"

# Boolean field that may be absent
value: "{{ boolTernary (boolDefault .spec.suspend false) \"Suspended\" \"Active\" }}"

Examples

# First non-empty image source
image: "{{ coalesce .spec.image .spec.defaultImage \"nginx:latest\" }}"

# Default replicas when not specified
replicas: "{{ default .spec.replicas 2 }}"

# Conditional resource creation
when:
  - field: spec.monitoring
    operator: notExists