Skip to content

Commit

Permalink
improve docs
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Hoß <[email protected]>
  • Loading branch information
sebhoss committed Dec 26, 2023
1 parent c998247 commit f57ea17
Show file tree
Hide file tree
Showing 3 changed files with 1,453 additions and 1,805 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ Replace `<version>` with the latest available [release](https://crates.io/crates
Each group of a Kubernetes custom resource has a corresponding Cargo feature in this crate. The group of a custom resource can be seen in the `apiVersion` field of a resource, e.g.:

```yaml
apiVersion: cert-manager.io/v1
kind: Issuer
apiVersion: chaos-mesh.org/v1alpha1
kind: PodNetworkChaos
metadata:
...
```
In the above example, `cert-manager.io` is the group and `v1` is the version. Since Cargo imposes certain rules on how features can be named, `.`, `-`, and `/` are all mapped to `_`. Therefore, the feature that contains the custom resource from the example above is called `cert_manager_io` and can be enabled like this:
In the above example, `chaos-mesh.org` is the group and `v1alpha1` is the version. Since Cargo imposes certain rules on how features can be named, `.`, `-`, and `/` are all mapped to `_`. Therefore, the feature that contains the custom resource from the example above is called `chaos_mesh_org` and can be enabled like this:

```toml
[dependencies]
kube-custom-resources-rs = { version = "<version>", features = ["cert_manager_io"] }
kube-custom-resources-rs = { version = "<version>", features = ["chaos_mesh_org"] }
```

Each version within a group has a corresponding module in that feature, e.g. there is a module called `v1` in the feature `cert_manager_io`.
Each version within a group has a corresponding module in that feature, e.g. there is a module called `v1alpha1` in the feature `chaos_mesh_org`.

Take a look at the [docs](https://docs.rs/kube-custom-resources-rs/latest/kube_custom_resources_rs/) to see all available features and the group/version/kinds they contain.

Expand All @@ -51,8 +51,8 @@ Updates to all CRDs are fetched [automatically](https://github.com/metio/kube-cu
The generated Rust code can be used as a [kube::Resource](https://docs.rs/kube/*/kube/trait.Resource.html) similar to this:

```rust
let issuers: Api<Issuer> = Api::default_namespaced(client);
let issuer = Issuer::new("example", IssuerSpec::default());
let api: Api<PodNetworkChaos> = Api::default_namespaced(client);
let resource = PodNetworkChaos::new("example", PodNetworkChaosSpec::default());
println!("doc: {:?}", issuer);
```

Expand Down
7 changes: 3 additions & 4 deletions code-generator/src/bin/lib_rs_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() -> Result<()> {
let mut buffer = BufWriter::new(file);

writeln!(buffer, "/*!")?;
writeln!(buffer, "This crate contains [kube-rs](https://kube.rs/) compatible bindings for Kubernetes [custom resources](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/). Each binding is generated with [kopium](https://github.com/kube-rs/kopium) and updated weekly.")?;
writeln!(buffer, "This crate contains [kube-rs](https://kube.rs/) compatible bindings for Kubernetes [custom resources](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/). Each binding is generated with [kopium](https://github.com/kube-rs/kopium), updated weekly, and released monthly.")?;
writeln!(buffer, "")?;
writeln!(buffer, "# Available Features")?;
writeln!(buffer, "")?;
Expand Down Expand Up @@ -73,11 +73,10 @@ fn main() -> Result<()> {

for (version, kinds) in versions.iter().sorted_by_key(|x| x.0) {
writeln!(buffer, "")?;
writeln!(buffer, "- apiVersion: `{}/{}`", group, version)?;
writeln!(buffer, "- kinds:")?;
writeln!(buffer, "apiVersion `{}/{}`:", group, version)?;

for crd in kinds {
writeln!(buffer, " - `{}`", crd.spec.names.kind)?;
writeln!(buffer, "- `{}`", crd.spec.names.kind)?;
}
}
}
Expand Down
Loading

0 comments on commit f57ea17

Please sign in to comment.