Math Notes

2 min read

Math notes perform arithmetic on numeric values from the CR spec. All math notes accept int, int64, float64, or numeric strings — they handle the mixed types that come out of Kubernetes unstructured objects without requiring explicit conversions.

Reference

NoteDescription
addAdd two numbers.
subSubtract the second number from the first.
mulMultiply two numbers.
divDivide the first number by the second.
modInteger modulo.
minReturn the smaller of two numbers.
maxReturn the larger of two numbers.
clampConstrain a value to the range [lo, hi].
absReturn the absolute value of a number.

Examples

# add
# value: "{{ add .spec.basePort 1000 }}"
# basePort=8080 → 9080

# sub
# value: "{{ sub .spec.replicas 1 }}"
# replicas=3 → 2

# mul
# value: "{{ mul .spec.replicas 2 }}"
# replicas=3 → 6

# div
# value: "{{ div .spec.totalWorkers 4 }}"
# totalWorkers=8 → 2

# mod
# value: "{{ mod .spec.port 100 }}"
# port=8080 → 80

# min
# Cap replicas at 10
# value: "{{ min .spec.replicas 10 }}"
# replicas=15 → 10
# replicas=3  → 3

# max
# Ensure at least 2 replicas
# value: "{{ max .spec.replicas 2 }}"
# replicas=1 → 2
# replicas=5 → 5

# clamp
# value: "{{ clamp .spec.replicas 1 20 }}"
# replicas=0  → 1
# replicas=5  → 5
# replicas=25 → 20

# abs
# value: "{{ abs .spec.offsetSeconds }}"
# -300 → 300
#  300 → 300
# Total memory limit = replicas × per-pod limit, capped at cluster max
# value: "{{ clamp (mul .spec.replicas .spec.memoryPerPod) 0 65536 }}"
# Port = base + index (forEach: as index)
# value: "{{ add .spec.basePort .index }}"