Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ jobs:
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
with:
key: test
- run: cargo test
- run: cargo test --all-features

tests_passed:
name: All tests passed
Expand Down
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/stackable-operator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ repository.workspace = true
time = ["dep:time"]

[dependencies]
stackable-operator-derive = { path = "../stackable-operator-derive", version = "0.3.1" }
stackable-shared = { path = "../stackable-shared", version = "0.0.1" }
stackable-operator-derive = { path = "../stackable-operator-derive" }
stackable-shared = { path = "../stackable-shared" }

chrono.workspace = true
clap.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion crates/stackable-versioned-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ proc-macro = true

[features]
full = ["k8s"]
k8s = ["dep:kube", "dep:k8s-openapi"]
k8s = ["dep:kube", "dep:k8s-openapi", "dep:stackable-shared"]

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

convert_case.workspace = true
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 40 additions & 2 deletions crates/stackable-versioned-macros/src/codegen/vstruct/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,51 @@ impl VersionedStruct {

#[automatically_derived]
impl #enum_ident {
/// Generates a merged CRD which contains all versions defined using the
/// `#[versioned()]` macro.
/// Generates a merged CRD which contains all versions defined using the `#[versioned()]` macro.
pub fn merged_crd(
stored_apiversion: Self
) -> ::std::result::Result<::k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition, ::kube::core::crd::MergeError> {
::kube::core::crd::merge_crds(vec![#(#crd_fn_calls),*], &stored_apiversion.to_string())
}

/// Generates and writes a merged CRD which contains all versions defined using the `#[versioned()]`
/// macro to a file located at `path`.
pub fn write_merged_crd<P>(path: P, stored_apiversion: Self, operator_version: &str) -> Result<(), ::stackable_versioned::Error>
where P: AsRef<::std::path::Path>
{
use ::stackable_shared::yaml::{YamlSchema, SerializeOptions};

let merged_crd = Self::merged_crd(stored_apiversion).map_err(|err| ::stackable_versioned::Error::MergeCrd {
source: err,
})?;

YamlSchema::write_yaml_schema(
&merged_crd,
path,
operator_version,
SerializeOptions::default()
).map_err(|err| ::stackable_versioned::Error::SerializeYaml {
source: err,
})
}

/// Generates and writes a merged CRD which contains all versions defined using the `#[versioned()]`
/// macro to stdout.
pub fn print_merged_crd(stored_apiversion: Self, operator_version: &str) -> Result<(), ::stackable_versioned::Error> {
use ::stackable_shared::yaml::{YamlSchema, SerializeOptions};

let merged_crd = Self::merged_crd(stored_apiversion).map_err(|err| ::stackable_versioned::Error::MergeCrd {
source: err,
})?;

YamlSchema::print_yaml_schema(
&merged_crd,
operator_version,
SerializeOptions::default()
).map_err(|err| ::stackable_versioned::Error::SerializeYaml {
source: err,
})
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/stackable-versioned/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ All notable changes to this project will be documented in this file.

### Added

- Add YAML serialization for merged CRD schema. The schema can now be printed to stdout or written
to file ([#884]).
- Add snapshot tests to verify generated code matches expected output ([#881]).

[#881]: https://github.com/stackabletech/operator-rs/pull/881
[#884]: https://github.com/stackabletech/operator-rs/pull/884

## [0.3.0] - 2024-09-26

Expand Down
12 changes: 10 additions & 2 deletions crates/stackable-versioned/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ all-features = true

[features]
full = ["k8s"]
# Forward the k8s feature to the underlying macro crate
k8s = ["stackable-versioned-macros/k8s"]
k8s = [
"stackable-versioned-macros/k8s", # Forward the k8s feature to the underlying macro crate
"dep:stackable-shared",
"dep:snafu",
"dep:kube",
]

[dependencies]
stackable-versioned-macros = { path = "../stackable-versioned-macros" }
stackable-shared = { path = "../stackable-shared", optional = true }

kube = { workspace = true, optional = true }
snafu = { workspace = true, optional = true }
13 changes: 13 additions & 0 deletions crates/stackable-versioned/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,21 @@
//! See [`versioned`] for an in-depth usage guide and a list of supported
//! parameters.

// Re-export macro
pub use stackable_versioned_macros::*;

#[cfg(feature = "k8s")]
#[derive(Debug, snafu::Snafu)]
pub enum Error {
#[snafu(display("failed to merge CRDs"))]
MergeCrd { source: kube::core::crd::MergeError },

#[snafu(display("failed to serialize YAML"))]
SerializeYaml {
source: stackable_shared::yaml::Error,
},
}

// Unused for now, might get picked up again in the future.
#[doc(hidden)]
pub trait AsVersionStr {
Expand Down
Loading