kube-cel
Kubernetes CEL extension functions for Rust, built on top of cel.
Implements the Kubernetes-specific CEL libraries defined in k8s.io/apiserver/pkg/cel/library and cel-go/ext, enabling client-side evaluation of CRD validation rules.
Installation
[]
= "0.3"
= "0.12"
Usage
use ;
use register_all;
let mut ctx = default;
register_all;
// String functions
let result = compile
.unwrap.execute.unwrap;
// Quantity comparison
let result = compile
.unwrap.execute.unwrap;
// Semver
let result = compile
.unwrap.execute.unwrap;
CRD Validation Pipeline
With the validation feature, you can compile and evaluate x-kubernetes-validations CEL rules client-side — no API server required.
[]
= { = "0.3", = ["validation"] }
use Validator;
use json;
let schema = json!;
let object = json!;
let validator = new;
let errors = validator.validate;
assert_eq!;
assert_eq!;
assert_eq!;
The validator walks the schema tree, compiles rules at each node, and evaluates them with self bound to the corresponding object value. Transition rules (referencing oldSelf) are supported by passing old_object.
Schema-aware format support
Fields with format: "date-time" or format: "duration" in the schema are automatically converted to CEL Timestamp / Duration values, matching K8s API server behavior:
let schema = json!;
Invalid strings gracefully fall back to Value::String.
Supported Functions
Strings
charAt, indexOf, lastIndexOf, lowerAscii, upperAscii, replace, split, substring, trim, join, strings.quote
Lists
isSorted, sum, min, max, indexOf, lastIndexOf, slice, flatten, reverse, distinct
Sets
sets.contains, sets.equivalent, sets.intersects
Regex
find, findAll
URLs
url, isURL, getScheme, getHost, getHostname, getPort, getEscapedPath, getQuery
IP / CIDR
ip, isIP, ip.isCanonical, family, isLoopback, isUnspecified, isLinkLocalMulticast, isLinkLocalUnicast, isGlobalUnicast, cidr, isCIDR, containsIP, containsCIDR, prefixLength, masked
Semver
semver, isSemver, major, minor, patch, isGreaterThan, isLessThan, compareTo
Quantity
quantity, isQuantity, isInteger, asInteger, asApproximateFloat, sign, add, sub, isGreaterThan, isLessThan, compareTo
Format
<string>.format(<list>) with verbs: %s, %d, %f, %e, %b, %o, %x, %X
Feature Flags
All features are enabled by default. Disable with default-features = false and pick what you need:
| Feature | Dependencies | Description |
|---|---|---|
strings |
- | String extension functions |
lists |
- | List extension functions |
sets |
- | Set operations |
regex_funcs |
regex |
Regex find/findAll |
urls |
url |
URL parsing and accessors |
ip |
ipnet |
IP/CIDR parsing and operations |
semver_funcs |
semver |
Semantic versioning |
format |
- | String formatting |
quantity |
- | Kubernetes resource quantities |
validation |
serde_json, serde, chrono |
CRD validation pipeline (compile + evaluate x-kubernetes-validations, format: date-time/duration) |
Related
- kube-rs - Rust Kubernetes client and controller runtime
- cel - Rust CEL interpreter
- Kubernetes CEL docs
License
Apache-2.0