Function kube_core::crd::v1::merge_crds

source ·
pub fn merge_crds(
    crds: Vec<CustomResourceDefinition>,
    stored_apiversion: &str,
) -> Result<CustomResourceDefinition, MergeError>
Expand description

Merge a collection of crds into a single multiversion crd

Given multiple CustomResource derived types granting CRDs via CustomResourceExt::crd, we can merge them into a single CRD with multiple CRDVersion objects, marking only the specified apiversion as storage: true.

This merge algorithm assumes that every CRD:

  • exposes exactly one CRDVersion
  • uses identical values for spec.group, spec.scope, and spec.names.kind

This is always true for CustomResource derives.

§Usage

use kube::core::crd::merge_crds;
let crds = vec![mycrd_v1, mycrd_v2];
let multi_version_crd = merge_crds(crds, "v1").unwrap();

Note the merge is done by marking the:

  • crd containing the stored_apiversion as the place the other crds merge their CRDVersion items
  • stored version is marked with storage: true, while all others get storage: false