Documentation
¶
Overview ¶
Package note provides the Orkestra template function library.
A note is a pure, named transformation function available in every template expression across the Orkestra runtime — conversion paths, status fields, mutation rules, when conditions, onCreate templates.
The name aligns with Orkestra's musical identity. Notes are the atomic units from which music is composed. In Orkestra, notes are the atomic units from which declarative operator behavior is composed — small, precise, and available everywhere a template expression is evaluated.
Notes are pure functions. They receive values and return transformed values. They cannot perform I/O, call external APIs, or produce side effects. For those, use Go hooks.
Usage in a Katalog:
conversion:
paths:
- from: v1
to: v2
spec:
schedule:
minute: "{{ cronMinute .spec.schedule }}"
hour: "{{ cronHour .spec.schedule }}"
status:
fields:
- path: environment
value: "{{ toLower .spec.environment }}"
- path: replicas
value: "{{ default .spec.replicas 2 }}"
- path: schedule
value: "{{ cronExpr .spec.schedule.minute .spec.schedule.hour .spec.schedule.dayOfMonth .spec.schedule.month .spec.schedule.dayOfWeek }}"
pkg/note/random.go
Random generation notes — for use with once: true on secrets.
IMPORTANT: These notes are pure in the mathematical sense — they produce random output. They are NOT idempotent. They MUST only be used in template sources that declare once: true (SecretTemplateSource.Once), which ensures the template is only evaluated once (when the Secret does not yet exist).
Using random notes without once: true causes a new value to be generated on every reconcile cycle — passwords change every 30 seconds, breaking every application that uses them.
Correct usage:
secrets:
- name: "{{ .metadata.name }}-credentials"
once: true # ← REQUIRED with random notes
data:
password: "{{ randomAlphanumeric 32 }}"
apiKey: "{{ randomHex 16 }}"
The notes are registered in note.Map() and available in all template expressions — the once: guard is the semantic safeguard, not a code restriction.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Map ¶
Map returns the complete Orkestra note library as a template.FuncMap. The map is built once and returned on every call — no allocation overhead.
Integrate into the resolver:
tmpl, err := template.New("f").
Option("missingkey=zero").
Funcs(note.Map()).
Parse(value)
func OrkLen ¶
func OrkLen(v interface{}) int
OrkLen returns the length of a string, slice, or map. Named orkLen to avoid shadowing Go's built-in len. Registered in note.Map() as "len" since Go templates do not have a built-in len that handles all three types uniformly.
Template: {{ len .spec.regions }} → 3 (slice with 3 elements) Template: {{ len .spec.schedule }} → 5 (map with 5 fields) Template: {{ len .metadata.name }} → 12 (string length)
func TypeOf ¶
func TypeOf(v interface{}) string
typeOf — returns the runtime type name of any value. orkLen — returns the length of a string, slice, or map.
typeOf is used in:
- Template expressions: {{ typeOf .spec.schedule }} → "string" or "map"
- when: conditions: operator: typeOf, value: map
The condition operator path uses NavigateRawPath → note.TypeOf directly. The template expression path uses the FuncMap entry registered in note.Map(). Both must return the same strings for the Katalog to be predictable.
Type strings (match Python/JavaScript convention for familiarity):
"string" → Go string
"number" → Go float64, int64, int (JSON numbers come back as float64)
"bool" → Go bool
"map" → Go map[string]interface{} (YAML objects, structured fields)
"slice" → Go []interface{} (YAML arrays, list fields)
"null" → nil
"unknown" → any other type
YAML type behaviour:
spec:
schedule: "*/5 * * * *" → typeOf returns "string"
schedule: → typeOf returns "map"
minute: "*/5"
regions: [us-east-1, eu-west-1] → typeOf returns "slice"
replicas: 3 → typeOf returns "number"
enabled: true → typeOf returns "bool"
TypeOf returns the type name of any interface{} value. Exported so pkg/types/when.go can call it from EvaluateOneCond without the template engine being involved.
Types ¶
This section is empty.