Math Notes

1 min read

Arithmetic on spec fields. All notes accept string, int64, or float64. Return int64 when the result is a whole number, float64 otherwise.

Reference

NoteSignatureReturns
adda, bnumber
suba, bnumber
mula, bnumber
diva, bnumber
moda, bint64
mina, bnumber
maxa, bnumber
clampval, lo, hinumber
absanumber

Examples

# Port arithmetic
port: "{{ add .spec.basePort 1000 }}"

# Enforce replica bounds
replicas: "{{ clamp .spec.replicas 2 20 }}"

# Default floor
replicas: "{{ max .spec.replicas 1 }}"

# Tenant resource quota: 1/4 of the declared CPU limit
cpu: "{{ formatQuantity (div (parseQuantity .spec.cpuLimit) 4) }}"

Compose with resource quantity notes for Kubernetes CPU/memory arithmetic.