Skip to content

Commit 2330336

Browse files
committed
feat(stackable-versioned): Add YAML serialization for merged CRD
1 parent 194d33e commit 2330336

File tree

4 files changed

+64
-5
lines changed

4 files changed

+64
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/stackable-versioned-macros/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ proc-macro = true
2222

2323
[features]
2424
full = ["k8s"]
25-
k8s = ["dep:kube", "dep:k8s-openapi"]
25+
k8s = ["dep:kube", "dep:k8s-openapi", "dep:stackable-shared"]
2626

2727
[dependencies]
28+
stackable-shared = { path = "../stackable-shared", optional = true }
2829
k8s-version = { path = "../k8s-version", features = ["darling"] }
2930

3031
convert_case.workspace = true

crates/stackable-versioned-macros/fixtures/snapshots/stackable_versioned_macros__test__k8s_snapshots.snap

Lines changed: 29 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/stackable-versioned-macros/src/codegen/vstruct/mod.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,43 @@ impl VersionedStruct {
382382

383383
#[automatically_derived]
384384
impl #enum_ident {
385-
/// Generates a merged CRD which contains all versions defined using the
386-
/// `#[versioned()]` macro.
385+
/// Generates a merged CRD which contains all versions defined using the `#[versioned()]` macro.
387386
pub fn merged_crd(
388387
stored_apiversion: Self
389388
) -> ::std::result::Result<::k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition, ::kube::core::crd::MergeError> {
390389
::kube::core::crd::merge_crds(vec![#(#crd_fn_calls),*], &stored_apiversion.to_string())
391390
}
391+
392+
/// Generates and writes a merged CRD which contains all versions defined using the `#[versioned()]`
393+
/// macro to a file located at `path`.
394+
pub fn write_merged_crd<P>(path: P, stored_apiversion: Self, operator_version: &str)
395+
where P: AsRef<::std::path::Path>
396+
{
397+
use ::stackable_shared::yaml::{YamlSchema, SerializeOptions};
398+
399+
let merged_crd = Self::merged_crd(stored_apiversion).unwrap();
400+
401+
YamlSchema::write_yaml_schema(
402+
&merged_crd,
403+
path,
404+
operator_version,
405+
SerializeOptions::default()
406+
).unwrap();
407+
}
408+
409+
/// Generates and writes a merged CRD which contains all versions defined using the `#[versioned()]`
410+
/// macro to stdout.
411+
pub fn print_merged_crd(stored_apiversion: Self, operator_version: &str) {
412+
use ::stackable_shared::yaml::{YamlSchema, SerializeOptions};
413+
414+
let merged_crd = Self::merged_crd(stored_apiversion).unwrap();
415+
416+
YamlSchema::print_yaml_schema(
417+
&merged_crd,
418+
operator_version,
419+
SerializeOptions::default()
420+
).unwrap();
421+
}
392422
}
393423
}
394424
}

0 commit comments

Comments
 (0)