kopium

CI Crates.io

Kubernetes openapi unmangler.

Generates rust structs from customresourcedefinitions in your kubernetes cluster follwing the spec/status model, by using their embedded openapi schema.

⚠️ WARNING: ALPHA SOFTWARE ⚠️

Requirements:

Installation

Grab a prebuilt musl/darwin binary from the latest release, or install from crates.io:

sh cargo install kopium

Usage

sh kopium prometheusrules.monitoring.coreos.com > prometheusrule.rs rustfmt +nightly --edition 2021 prometheusrule.rs

Output

```rust use kube::CustomResource; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap;

[derive(CustomResource, Serialize, Deserialize, Clone, Debug)]

[kube(

group = "monitoring.coreos.com",
version = "v1",
kind = "PrometheusRule",
plural = "prometheusrules"

)]

[kube(namespaced)]

[kube(schema = "disabled")]

pub struct PrometheusRuleSpec { #[serde(default, skipserializingif = "Vec::is_empty")] pub groups: Vec, }

[derive(Serialize, Deserialize, Clone, Debug)]

pub struct PrometheusRuleGroups { pub interval: Option, pub name: String, pub partialresponsestrategy: Option, pub rules: Vec, }

[derive(Serialize, Deserialize, Clone, Debug)]

pub struct PrometheusRuleGroupsRules { pub alert: Option, #[serde(default, skipserializingif = "BTreeMap::isempty")] pub annotations: BTreeMap, pub expr: String, pub r#for: Option, #[serde(default, skipserializingif = "BTreeMap::isempty")] pub labels: BTreeMap, pub record: Option, } ```

Testing

Generate a CRD, tell the test runner to try to use it.

sh cargo run --bin kopium -- prometheusrules.monitoring.coreos.com > tests/gen.rs echo "pub type CR = PrometheusRule;" >> tests/gen.rs kubectl apply -f tests/pr.yaml # needs to contain a CR with name "gen" cargo test --test runner -- --nocapture

Requires kubernetes access to write customresourcedefinitions.