kopium
Kubernetes openapi unmangler.
Generates rust structs from customresourcedefinitions in your kubernetes cluster following the spec/status model, by using their embedded openapi schema.
⚠️ WARNING: not feature complete ⚠️
Requirements:
- stable
customresourcedefinitionwith schema - crd following standard spec/status model
Features
- Instantly queryable: generated type uses
kube-deriveto provide api integration withkube - Rust doc comments: optionally extracted from
descriptionvalues in schema - Safe case conversion: generated types uses rust standard camel_case with occasional serde rename attributes
- Usable locally and in CI: Can read crds by name in cluster via
mycrd.group.ioor from file via-f crd.yaml
Installation
Grab a prebuilt directly / via binstall, or install from crates.io:
Usage
If you have a crd installed in your cluster, pass a crd name accessible from your KUBECONFIG:
Or pass a file/stdin via -f:
|
Output
use CustomResource;
use JsonSchema;
use ;
use BTreeMap;
use IntOrString;
/// Specification of desired alerting rule definitions for Prometheus.
/// RuleGroup is a list of sequentially evaluated recording and alerting rules.
/// Rule describes an alerting or recording rule
Usage with kube
Add the generated file (e.g. output from above in prometheusrule.rs) to your library, and import (at least) the special root type:
use PrometheusRule;
use ;
async
Note that you will need to depend on kube, along with k8s-openapi and schemars at semver compatible versions with the latest kube release (which can be seen in the last release cargo.toml for kube). E.g. with kube 1:
= { = "1", = ["derive"] }
= { = "0.8" }
= { = "0.25", = ["latest", "schemars"] }
Autocomplete
Autocompletion for most shells available via kopium completions:
Testing
Unit tests and running kopium from a file do not require a cluster and can be run with:
Full integration tests use your current cluster to try to read a CRD and a gen object (instance of the CRD type) and parse it into the generated type:
test shortcuts available via just in the justfile and run pre-merge.
Existing Bindings
Certain binding libraries publish the kopium output up to crates.io for easier consumption, and this can avoid having to inline generated files in your repo (provided you do not need customization / patches to the output).
The main catalogue library is metio/kube-custom-resources-rs which selects crds via features (don't use all-features).
Specific group binding libraries:
Feel free to edit this file to add more.
License
Apache 2.0 licensed. See LICENSE for details.