Documentation
¶
Overview ¶
Package kel is KEL, the Kubernetes Expression Library: functions that know Kubernetes, for any Go template or expression engine. It is a library, not a language: no parser, no grammar, no runtime of its own.
FuncMap returns every function as a template.FuncMap, and Builtin describes them: domain, description, example and keywords, from their doc comments. Register adds your own functions beside KEL's, and Override replaces one on purpose.
The functions live in three packages, by what they read:
- core: plain values (strings, numbers, time, cron, collections, …)
- kube: Kubernetes objects, in the shape the API returns them
- ecosystem: what the tools around Kubernetes produce, such as a Prometheus query result or a container image reference
Every function takes its inputs as arguments and does no I/O: a function about pods is given the pods.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var BuiltinDomains = []DomainInfo{
{Name: "collections", Title: "Collections", Intro: "Convert a value that may arrive in several shapes (a native list or map, or the same as a JSON or YAML string) into a list, a map or a string, so the functions after it see one shape.\n\nRead lists and maps without guarding every step: get an element by index or a value by key, test membership, take keys and values, or keep and drop keys. Out-of-range and missing keys give zero values, not errors."},
{Name: "conditional", Title: "Conditional", Intro: "Choose between values inside an expression: defaults for empty values, the first non-empty of several, and ternaries, so a template does not need an if block for a one-line choice."},
{Name: "container", Title: "Container", Intro: "Read the containers of a workload (a Deployment, StatefulSet, Job, Pod, …, through its pod template): images, environment variables, ports and counts, by container index or name."},
{Name: "cron", Title: "Cron", Intro: "Work with five-field cron expressions (minute hour day-of-month month day-of-week): read single fields, build and normalise expressions, convert between the string form and a map with one key per field, describe a schedule in words, and check that an expression is valid."},
{Name: "data", Title: "Data", Intro: "Encode, hash and shape values: base64, a short SHA-256 for content-addressed names, slugs and truncation that keep a value valid as a Kubernetes name, and lookup tables written inline in an expression."},
{Name: "domain", Title: "Domain", Intro: "Take domain names and URLs apart: the host of a URL, and a domain without its subdomain."},
{Name: "fields", Title: "Fields", Intro: "Read the fields every Kubernetes object has: name, namespace, UID, resource version, creation timestamp, labels and annotations."},
{Name: "hpa", Title: "HPA", Intro: "Read a HorizontalPodAutoscaler: current, desired, minimum and maximum replicas, whether it is scaling or at its limit, its conditions, its scale target and the types of metric it reports."},
{Name: "ingress", Title: "Ingress", Intro: "Read an Ingress: whether it has a load balancer address, its host and IP, its class, the hosts in its rules and TLS section, and every load balancer address."},
{Name: "job", Title: "Job", Intro: "Read Jobs and CronJobs: whether a Job succeeded, failed or is running, and when a CronJob last ran, last succeeded and runs next. The functions that look inside a Job's pods take the pods as a list."},
{Name: "kubernetes", Title: "Kubernetes", Intro: "Answer the questions about any Kubernetes object that every controller asks: its conditions and their reasons, whether it is ready, synced, terminating or exists, and the fields of its spec and status, read safely."},
{Name: "kubevalidation", Title: "Kubernetes validation", Intro: "Check values against the rules the API server applies to names and metadata: label keys and values, annotation keys, and DNS-1123 subdomains, so a bad value is caught with a clear message before the API server rejects it."},
{Name: "math", Title: "Math", Intro: "Arithmetic on values that may arrive as integers, floats or numeric strings: add, subtract, multiply, divide, modulo, absolute value, minimum, maximum and clamping. Division and modulo by zero are errors."},
{Name: "net", Title: "Net", Intro: "Check IP addresses and CIDR ranges: whether an address is valid, private, or inside a range."},
{Name: "node", Title: "Node", Intro: "Read a Node: readiness, allocatable CPU and memory, conditions, taints, and where it is (zone, region, instance type, from the well-known topology labels); and which node a pod is scheduled on."},
{Name: "pods", Title: "Pods", Intro: "Answer questions about a set of Pods, as the API returns them, passed as a list or a PodList: names, IPs, phases, nodes, readiness, restarts, and why containers are waiting or failed (CrashLoopBackOff, OOMKilled, ImagePullBackOff, …)."},
{Name: "prometheus", Title: "Prometheus", Intro: "Read the response of a Prometheus HTTP API instant query (/api/v1/query), the object with \"status\" and \"data\": the value, sums and maxima across series, thresholds, series counts and label values. No data gives zero values; a sample that does not parse is an error."},
{Name: "pvc", Title: "PVC", Intro: "Read a PersistentVolumeClaim (whether it is bound, its phase, capacity, storage class and access modes), the PersistentVolume bound to it, and its StorageClass."},
{Name: "quantity", Title: "Quantity", Intro: "Work with Kubernetes resource quantities (\"500m\", \"2Gi\"): parse, compare, add and subtract them, keeping the canonical form."},
{Name: "random", Title: "Random", Intro: "Generate cryptographically secure random values: hex, base64 and alphanumeric strings, and UUIDs. They return a different value on every call, so evaluate them once, when a secret is first created, and keep the result; evaluated on every reconcile, a password changes every time."},
{Name: "replica", Title: "Replica", Intro: "Read the replica counts of a workload (desired, ready, available and updated) and whether all replicas are ready or a rollout has completed."},
{Name: "replicaset", Title: "ReplicaSet", Intro: "Read a Deployment's ReplicaSets, passed as a list: how many, their names, and which are older than the Deployment's current revision; and any object's controller, from its ownerReferences."},
{Name: "safeaccess", Title: "Safe access", Intro: "Read a nested field and fall back to a default when it is absent or of the wrong type, typed as a string, an integer or a boolean."},
{Name: "semver", Title: "Semver", Intro: "Work with semantic versions (\"1.2.3\", \"v1.2.3-rc.1\"): read their parts, compare them, bump them, and check them against constraints such as \">= 1.20\". A version that does not parse is an error."},
{Name: "service", Title: "Service", Intro: "Read a Service (cluster IP, node port, load balancer IP and host) and its EndpointSlices, passed as one slice or a list: whether any endpoint is ready, and the endpoints as \"ip:port\"."},
{Name: "statefulset", Title: "StatefulSet", Intro: "Read what is particular to a StatefulSet: its current and update revisions, and the partition of a staged rolling update. Replica counts, rollout completion and pods have their own functions."},
{Name: "strings", Title: "Strings", Intro: "The string operations expressions need most: case, trimming, prefixes and suffixes, splitting and joining, concatenation, case conversion between camelCase and kebab-case, and shortening text for display."},
{Name: "time", Title: "Time", Intro: "Reason about timestamps (RFC3339) and durations (Go units plus d, w, mo and y): elapsed and remaining time, formatting, time windows and weekdays, duration arithmetic, and the next run of a cron schedule."},
{Name: "types", Title: "Types", Intro: "Inspect and convert types: what type a value has (map, slice, string, number, bool, null), whether it is empty, and conversion to strings, numbers, booleans, lists and JSON."},
{Name: "validation", Title: "Validation", Intro: "Check that free text is the kind of value it claims to be: an email address, a URL, JSON, a port number. A form field is free text until something checks it; catching a malformed value early, with a clear message, beats finding out downstream.\n\nCheck references to artifacts the tools around Kubernetes consume: a git repository (Argo CD, Flux) and a container image reference (registries). Catching a malformed one early beats finding out when the tool fails to reconcile it."},
{Name: "warnings", Title: "Warnings", Intro: "Answer questions about Kubernetes Events, as the API returns them (core/v1 or events.k8s.io/v1), passed as a list or an EventList. Only Warning events count, so a caller can pass all of an object's events."},
}
BuiltinDomains is every domain, from the builders' doc comments.
var BuiltinFunctions = []FunctionInfo{}/* 276 elements not displayed */
BuiltinFunctions is every function, from its doc comment.
Functions ¶
func FuncMap ¶
FuncMap returns KEL's functions as a template.FuncMap: a copy, so a caller can add its own (with Register) without changing KEL's.
tmpl, err := template.New("f").
Option("missingkey=zero").
Funcs(kel.FuncMap()).
Parse(value)
Types ¶
type DomainInfo ¶
type DomainInfo struct {
Name string // e.g. "cron"
Title string // e.g. "Cron"
Intro string // what the functions are for
}
DomainInfo describes one group of functions, from its builder's doc comment.
type FunctionInfo ¶
type FunctionInfo struct {
Name string // template name, e.g. "cronValid"
Domain string // e.g. "cron"
Description string // what it does
Example string // a template using it
SeeAlso []string // related functions
Keywords []string // search terms
}
FunctionInfo describes one function, from its doc comment.
type Registry ¶
type Registry struct {
Functions []FunctionInfo // sorted by domain, then name
Domains []DomainInfo // sorted by name
}
Registry is a set of documented functions and their domains. Builtin returns KEL's; a program that adds functions can merge its own with With.
func (Registry) ByDomain ¶
func (r Registry) ByDomain(domain string) []FunctionInfo
ByDomain returns the functions in domain (case-insensitive).
func (Registry) Domain ¶
func (r Registry) Domain(name string) (DomainInfo, bool)
Domain returns the domain called name (case-insensitive).
func (Registry) Get ¶
func (r Registry) Get(name string) (FunctionInfo, bool)
Get returns the function called name (case-insensitive).
func (Registry) Search ¶
func (r Registry) Search(term string) []FunctionInfo
Search returns the functions whose name, description, example or a keyword contains term (case-insensitive).
Directories
¶
| Path | Synopsis |
|---|---|
|
pkg/util/cron.go
|
pkg/util/cron.go |
|
Package ecosystem holds KEL's functions on what the tools around Kubernetes produce and consume: Prometheus query results, container image references, git repositories.
|
Package ecosystem holds KEL's functions on what the tools around Kubernetes produce and consume: Prometheus query results, container image references, git repositories. |
|
Command examples shows KEL on a Deployment in the middle of a rollout: from a template, from Go, and through the function registry.
|
Command examples shows KEL on a Deployment in the middle of a rollout: from a template, from Go, and through the function registry. |
|
Package gendoc reads KEL-style documentation from Go source: the doc comments of the functions a package registers, and of the builders that register them.
|
Package gendoc reads KEL-style documentation from Go source: the doc comments of the functions a package registers, and of the builders that register them. |
|
hack
|
|
|
generate
command
Command generate writes kel_generated.go, KEL's registry of functions and domains, from the doc comments in core, kube and ecosystem.
|
Command generate writes kel_generated.go, KEL's registry of functions and domains, from the doc comments in core, kube and ecosystem. |
|
internal
|
|
|
anymap
Package anymap reads the map[string]interface{} values KEL passes around, including named types built on it, such as kube.Map.
|
Package anymap reads the map[string]interface{} values KEL passes around, including named types built on it, such as kube.Map. |
|
funcmap
Package funcmap merges template function maps for KEL's packages: a name registered twice is a programming error, and replacing one must be said explicitly.
|
Package funcmap merges template function maps for KEL's packages: a name registered twice is a programming error, and replacing one must be said explicitly. |
|
testutil
Package testutil holds what KEL's tests share: reading fixtures as an API client would, and turning them into the typed client-go objects Go programs hold.
|
Package testutil holds what KEL's tests share: reading fixtures as an API client would, and turning them into the typed client-go objects Go programs hold. |
|
Package kube holds KEL's functions on Kubernetes objects, in the shape the API returns them: the map an unstructured or dynamic client gives, or JSON decoded into a map.
|
Package kube holds KEL's functions on Kubernetes objects, in the shape the API returns them: the map an unstructured or dynamic client gives, or JSON decoded into a map. |