when / anyOf conditions

2 min read

Conditions control whether a resource template field is written during reconciliation. Used inside operatorBox and autoscale.

operatorBox:
  when:
    - field: spec.replicas
      operator: gt
      value: "1"
      valueType: int

  anyOf:
    - field: spec.mode
      equals: production
    - field: spec.mode
      equals: staging

Semantics

BlockBehaviour
whenAND — all conditions must be true
anyOfOR — at least one condition must be true

Both can be combined. The overall result is: when AND anyOf.

Condition fields

FieldRequiredDescription
fieldyesDot-notation path into the CR (e.g. spec.replicas, spec.config.mode)
operatoryes*Comparison operator (see below)
valueyes*Value to compare against
valueTypenostring (default), int, float, bool

*Use either the operator+value form or a shorthand form — not both.

Operators

OperatorShorthandDescription
eqequalsField equals value
neqnotEqualsField does not equal value
gtgreaterThanField is greater than value (numeric)
ltlessThanField is less than value (numeric)
gteminField is greater than or equal to value (numeric)
ltemaxField is less than or equal to value (numeric)
containscontainsField contains the substring
prefixprefixField starts with the value
suffixsuffixField ends with the value

Shorthand form

when:
  - field: spec.engine
    equals: postgres         # shorthand for operator: eq, value: postgres

  - field: spec.replicas
    greaterThan: "0"         # shorthand for operator: gt
    valueType: int

Explicit form

when:
  - field: spec.replicas
    operator: gt
    value: "3"
    valueType: int

→ Next: validation.md