From 9c27f98685c2c3b677ec1b515185e8890471768a Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Tue, 1 Dec 2026 16:09:54 +0100 Subject: [PATCH 1/3] fix(versioned): Respect version-level `skip(from)` flag --- .../src/codegen/container/struct/mod.rs | 5 ++- .../tests/inputs/pass/skip_from_version.rs | 35 ++++++++++++++++ ..._snapshots__pass@skip_from_version.rs.snap | 42 +++++++++++++++++++ .../tests/trybuild.rs | 1 + crates/stackable-versioned/CHANGELOG.md | 4 ++ 5 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 crates/stackable-versioned-macros/tests/inputs/pass/skip_from_version.rs create mode 100644 crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@skip_from_version.rs.snap diff --git a/crates/stackable-versioned-macros/src/codegen/container/struct/mod.rs b/crates/stackable-versioned-macros/src/codegen/container/struct/mod.rs index f10fe243d..2d0ab28ad 100644 --- a/crates/stackable-versioned-macros/src/codegen/container/struct/mod.rs +++ b/crates/stackable-versioned-macros/src/codegen/container/struct/mod.rs @@ -465,7 +465,10 @@ impl Struct { ver_ctx: VersionContext<'_>, mod_gen_ctx: ModuleGenerationContext<'_>, ) -> Option { - if mod_gen_ctx.skip.from.is_present() || self.common.options.skip_from { + if mod_gen_ctx.skip.from.is_present() + || ver_ctx.version.skip_from + || self.common.options.skip_from + { return None; } diff --git a/crates/stackable-versioned-macros/tests/inputs/pass/skip_from_version.rs b/crates/stackable-versioned-macros/tests/inputs/pass/skip_from_version.rs new file mode 100644 index 000000000..0113524c2 --- /dev/null +++ b/crates/stackable-versioned-macros/tests/inputs/pass/skip_from_version.rs @@ -0,0 +1,35 @@ +use stackable_versioned::versioned; +// --- +#[versioned( + version(name = "v1alpha1", skip(from)), + version(name = "v1alpha2"), + version(name = "v1beta1") +)] +// --- +mod versioned { + struct Foo { + #[versioned(removed(in = "v1alpha2"))] + bar: usize, + + #[versioned(added(in = "v1alpha2"))] + baz: usize, + + #[versioned(added(in = "v1beta1"))] + qux: String, + } +} +// --- +fn main() {} + +// The From impls between v1alpha1 and v1alpha2 are skipped and implemented manually instead. +impl From for v1alpha2::Foo { + fn from(foo: v1alpha1::Foo) -> Self { + Self { baz: foo.bar } + } +} + +impl From for v1alpha1::Foo { + fn from(foo: v1alpha2::Foo) -> Self { + Self { bar: foo.baz } + } +} diff --git a/crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@skip_from_version.rs.snap b/crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@skip_from_version.rs.snap new file mode 100644 index 000000000..cac877a9e --- /dev/null +++ b/crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@skip_from_version.rs.snap @@ -0,0 +1,42 @@ +--- +source: crates/stackable-versioned-macros/src/lib.rs +expression: formatted +input_file: crates/stackable-versioned-macros/tests/inputs/pass/skip_from_version.rs +--- +#[automatically_derived] +mod v1alpha1 { + use super::*; + pub struct Foo { + pub bar: usize, + } +} +#[automatically_derived] +mod v1alpha2 { + use super::*; + pub struct Foo { + pub baz: usize, + } +} +#[automatically_derived] +impl ::core::convert::From for v1beta1::Foo { + fn from(__sv_foo: v1alpha2::Foo) -> Self { + Self { + baz: __sv_foo.baz.into(), + qux: ::std::default::Default::default(), + } + } +} +#[automatically_derived] +impl ::core::convert::From for v1alpha2::Foo { + fn from(__sv_foo: v1beta1::Foo) -> Self { + Self { baz: __sv_foo.baz.into() } + } +} +#[automatically_derived] +mod v1beta1 { + use super::*; + pub struct Foo { + pub baz: usize, + pub qux: String, + } +} diff --git a/crates/stackable-versioned-macros/tests/trybuild.rs b/crates/stackable-versioned-macros/tests/trybuild.rs index 9621685bb..32f68e6f8 100644 --- a/crates/stackable-versioned-macros/tests/trybuild.rs +++ b/crates/stackable-versioned-macros/tests/trybuild.rs @@ -42,6 +42,7 @@ mod inputs { // mod scale; // mod selectable; // mod shortnames; + // mod skip_from_version; // mod submodule; } diff --git a/crates/stackable-versioned/CHANGELOG.md b/crates/stackable-versioned/CHANGELOG.md index ee0b92aa7..2426cccb0 100644 --- a/crates/stackable-versioned/CHANGELOG.md +++ b/crates/stackable-versioned/CHANGELOG.md @@ -22,10 +22,14 @@ All notable changes to this project will be documented in this file. strings ([#1326]). - The generated tracking status now respects the `schemars` and `serde` crate overrides. Previously, it failed to compile if these crates were not direct dependencies ([#1326]). +- Structs now respect the version-level `skip(from)` flag, e.g. `version(name = "v1alpha1", skip(from))`. + Previously, only enums respected it, so the `From` impls between the flagged and the next version + were still generated for structs, which conflicted with manual implementations ([#XXXX]). [#1324]: https://github.com/stackabletech/operator-rs/pull/1324 [#1325]: https://github.com/stackabletech/operator-rs/pull/1325 [#1326]: https://github.com/stackabletech/operator-rs/pull/1326 +[#XXXX]: https://github.com/stackabletech/operator-rs/pull/XXXX ## [0.14.0] - 2026-11-03 From f275d85c4954951e9b6e57860d486b2e891eab46 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Tue, 1 Dec 2026 16:31:06 +0100 Subject: [PATCH 2/3] refactor: Add common helper function --- .../src/codegen/container/enum.rs | 2 +- .../src/codegen/container/mod.rs | 14 ++++- .../src/codegen/container/struct/mod.rs | 5 +- .../tests/inputs/pass/skip_from_module.rs | 56 +++++++++++++++++++ ...__snapshots__pass@skip_from_module.rs.snap | 28 ++++++++++ .../tests/trybuild.rs | 1 + crates/stackable-versioned/CHANGELOG.md | 5 +- 7 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 crates/stackable-versioned-macros/tests/inputs/pass/skip_from_module.rs create mode 100644 crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@skip_from_module.rs.snap diff --git a/crates/stackable-versioned-macros/src/codegen/container/enum.rs b/crates/stackable-versioned-macros/src/codegen/container/enum.rs index 0b254cde4..f8b4ecc88 100644 --- a/crates/stackable-versioned-macros/src/codegen/container/enum.rs +++ b/crates/stackable-versioned-macros/src/codegen/container/enum.rs @@ -143,7 +143,7 @@ impl Enum { ver_ctx: VersionContext<'_>, mod_gen_ctx: ModuleGenerationContext<'_>, ) -> Option { - if ver_ctx.version.skip_from || self.common.options.skip_from { + if self.common.skip_from(ver_ctx, mod_gen_ctx) { return None; } diff --git a/crates/stackable-versioned-macros/src/codegen/container/mod.rs b/crates/stackable-versioned-macros/src/codegen/container/mod.rs index b7ef4327c..f64b1f2cf 100644 --- a/crates/stackable-versioned-macros/src/codegen/container/mod.rs +++ b/crates/stackable-versioned-macros/src/codegen/container/mod.rs @@ -9,7 +9,7 @@ use syn::{Attribute, Ident}; use crate::{ attrs::container::StructCrdArguments, codegen::{ - VersionDefinition, + VersionContext, VersionDefinition, container::{r#enum::Enum, r#struct::Struct}, module::ModuleGenerationContext, }, @@ -32,6 +32,18 @@ pub struct CommonContainerData { pub idents: ContainerIdents, } +impl CommonContainerData { + /// Returns whether the `From` impls between `ver_ctx.version` and the next version should be + /// skipped, based on the module-, version- and container-level `skip(from)` flags. + pub fn skip_from( + &self, + ver_ctx: VersionContext<'_>, + mod_gen_ctx: ModuleGenerationContext<'_>, + ) -> bool { + mod_gen_ctx.skip.from.is_present() || ver_ctx.version.skip_from || self.options.skip_from + } +} + /// Supported types of containers, structs and enums. /// /// Abstracting away with kind of container is generated makes it possible to create a list of diff --git a/crates/stackable-versioned-macros/src/codegen/container/struct/mod.rs b/crates/stackable-versioned-macros/src/codegen/container/struct/mod.rs index 2d0ab28ad..142cda893 100644 --- a/crates/stackable-versioned-macros/src/codegen/container/struct/mod.rs +++ b/crates/stackable-versioned-macros/src/codegen/container/struct/mod.rs @@ -465,10 +465,7 @@ impl Struct { ver_ctx: VersionContext<'_>, mod_gen_ctx: ModuleGenerationContext<'_>, ) -> Option { - if mod_gen_ctx.skip.from.is_present() - || ver_ctx.version.skip_from - || self.common.options.skip_from - { + if self.common.skip_from(ver_ctx, mod_gen_ctx) { return None; } diff --git a/crates/stackable-versioned-macros/tests/inputs/pass/skip_from_module.rs b/crates/stackable-versioned-macros/tests/inputs/pass/skip_from_module.rs new file mode 100644 index 000000000..130719a44 --- /dev/null +++ b/crates/stackable-versioned-macros/tests/inputs/pass/skip_from_module.rs @@ -0,0 +1,56 @@ +use stackable_versioned::versioned; +// --- +#[versioned(version(name = "v1alpha1"), version(name = "v1alpha2"), skip(from))] +// --- +mod versioned { + struct Foo { + #[versioned(added(in = "v1alpha2"))] + bar: usize, + + baz: Baz, + } + + enum Baz { + #[versioned(changed(in = "v1alpha2", previous_name = "PrevA"))] + A, + B, + } +} +// --- +fn main() {} + +// The From impls of all containers are skipped and implemented manually instead. +impl From for v1alpha2::Foo { + fn from(foo: v1alpha1::Foo) -> Self { + Self { + bar: 42, + baz: foo.baz.into(), + } + } +} + +impl From for v1alpha1::Foo { + fn from(foo: v1alpha2::Foo) -> Self { + Self { + baz: foo.baz.into(), + } + } +} + +impl From for v1alpha2::Baz { + fn from(baz: v1alpha1::Baz) -> Self { + match baz { + v1alpha1::Baz::PrevA => Self::A, + v1alpha1::Baz::B => Self::B, + } + } +} + +impl From for v1alpha1::Baz { + fn from(baz: v1alpha2::Baz) -> Self { + match baz { + v1alpha2::Baz::A => Self::PrevA, + v1alpha2::Baz::B => Self::B, + } + } +} diff --git a/crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@skip_from_module.rs.snap b/crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@skip_from_module.rs.snap new file mode 100644 index 000000000..0f75096ce --- /dev/null +++ b/crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@skip_from_module.rs.snap @@ -0,0 +1,28 @@ +--- +source: crates/stackable-versioned-macros/src/lib.rs +expression: formatted +input_file: crates/stackable-versioned-macros/tests/inputs/pass/skip_from_module.rs +--- +#[automatically_derived] +mod v1alpha1 { + use super::*; + pub struct Foo { + pub baz: Baz, + } + pub enum Baz { + PrevA, + B, + } +} +#[automatically_derived] +mod v1alpha2 { + use super::*; + pub struct Foo { + pub bar: usize, + pub baz: Baz, + } + pub enum Baz { + A, + B, + } +} diff --git a/crates/stackable-versioned-macros/tests/trybuild.rs b/crates/stackable-versioned-macros/tests/trybuild.rs index 32f68e6f8..8bc02d02b 100644 --- a/crates/stackable-versioned-macros/tests/trybuild.rs +++ b/crates/stackable-versioned-macros/tests/trybuild.rs @@ -42,6 +42,7 @@ mod inputs { // mod scale; // mod selectable; // mod shortnames; + // mod skip_from_module; // mod skip_from_version; // mod submodule; } diff --git a/crates/stackable-versioned/CHANGELOG.md b/crates/stackable-versioned/CHANGELOG.md index 2426cccb0..42b23205a 100644 --- a/crates/stackable-versioned/CHANGELOG.md +++ b/crates/stackable-versioned/CHANGELOG.md @@ -24,12 +24,13 @@ All notable changes to this project will be documented in this file. it failed to compile if these crates were not direct dependencies ([#1326]). - Structs now respect the version-level `skip(from)` flag, e.g. `version(name = "v1alpha1", skip(from))`. Previously, only enums respected it, so the `From` impls between the flagged and the next version - were still generated for structs, which conflicted with manual implementations ([#XXXX]). + were still generated for structs, which conflicted with manual implementations. Likewise, enums now + respect the module-level `skip(from)` flag ([#1344]). [#1324]: https://github.com/stackabletech/operator-rs/pull/1324 [#1325]: https://github.com/stackabletech/operator-rs/pull/1325 [#1326]: https://github.com/stackabletech/operator-rs/pull/1326 -[#XXXX]: https://github.com/stackabletech/operator-rs/pull/XXXX +[#1344]: https://github.com/stackabletech/operator-rs/pull/1344 ## [0.14.0] - 2026-11-03 From 313b714e340b06648dc2c7add3e5ce21ba2bd268 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Tue, 1 Dec 2026 16:46:50 +0100 Subject: [PATCH 3/3] test: Increase test coverage --- .../src/codegen/mod.rs | 4 ++- crates/stackable-versioned-macros/src/lib.rs | 2 +- .../tests/inputs/pass/skip_from_version.rs | 27 ++++++++++++++++- ..._snapshots__pass@skip_from_version.rs.snap | 30 +++++++++++++++++++ crates/stackable-versioned/CHANGELOG.md | 5 ++-- 5 files changed, 63 insertions(+), 5 deletions(-) diff --git a/crates/stackable-versioned-macros/src/codegen/mod.rs b/crates/stackable-versioned-macros/src/codegen/mod.rs index 1e1117876..410c8b254 100644 --- a/crates/stackable-versioned-macros/src/codegen/mod.rs +++ b/crates/stackable-versioned-macros/src/codegen/mod.rs @@ -16,7 +16,9 @@ pub struct VersionDefinition { /// Indicates that the container version is deprecated. pub deprecated: Option, - /// Indicates that the generation of `From for NEW` should be skipped. + /// Indicates that the generation of the `From` impls (and `TrackingFrom` impls if conversion + /// tracking is enabled) between this and the next version should be skipped. This affects both + /// directions (upgrade and downgrade) of all containers in the module. pub skip_from: bool, /// A validated Kubernetes API version. diff --git a/crates/stackable-versioned-macros/src/lib.rs b/crates/stackable-versioned-macros/src/lib.rs index 358f63b03..500c0c8e0 100644 --- a/crates/stackable-versioned-macros/src/lib.rs +++ b/crates/stackable-versioned-macros/src/lib.rs @@ -1223,7 +1223,7 @@ mod snapshots { #[test] fn pass() { - // TODO (@Techassi): Re-add skip tests + // TODO (@Techassi): Re-add skip tests for object_from, merged_crd and try_convert let _settings_guard = test_utils::set_snapshot_path().bind_to_scope(); glob!("../tests/inputs/pass", "*.rs", |path| { diff --git a/crates/stackable-versioned-macros/tests/inputs/pass/skip_from_version.rs b/crates/stackable-versioned-macros/tests/inputs/pass/skip_from_version.rs index 0113524c2..4eb1bc78b 100644 --- a/crates/stackable-versioned-macros/tests/inputs/pass/skip_from_version.rs +++ b/crates/stackable-versioned-macros/tests/inputs/pass/skip_from_version.rs @@ -17,11 +17,18 @@ mod versioned { #[versioned(added(in = "v1beta1"))] qux: String, } + + enum Mode { + #[versioned(changed(in = "v1alpha2", previous_name = "PrevA"))] + A, + B, + } } // --- fn main() {} -// The From impls between v1alpha1 and v1alpha2 are skipped and implemented manually instead. +// The From impls of all containers between v1alpha1 and v1alpha2 are skipped and implemented +// manually instead. impl From for v1alpha2::Foo { fn from(foo: v1alpha1::Foo) -> Self { Self { baz: foo.bar } @@ -33,3 +40,21 @@ impl From for v1alpha1::Foo { Self { bar: foo.baz } } } + +impl From for v1alpha2::Mode { + fn from(mode: v1alpha1::Mode) -> Self { + match mode { + v1alpha1::Mode::PrevA => Self::A, + v1alpha1::Mode::B => Self::B, + } + } +} + +impl From for v1alpha1::Mode { + fn from(mode: v1alpha2::Mode) -> Self { + match mode { + v1alpha2::Mode::A => Self::PrevA, + v1alpha2::Mode::B => Self::B, + } + } +} diff --git a/crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@skip_from_version.rs.snap b/crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@skip_from_version.rs.snap index cac877a9e..af72ef275 100644 --- a/crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@skip_from_version.rs.snap +++ b/crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshots__pass@skip_from_version.rs.snap @@ -9,6 +9,10 @@ mod v1alpha1 { pub struct Foo { pub bar: usize, } + pub enum Mode { + PrevA, + B, + } } #[automatically_derived] mod v1alpha2 { @@ -16,6 +20,10 @@ mod v1alpha2 { pub struct Foo { pub baz: usize, } + pub enum Mode { + A, + B, + } } #[automatically_derived] impl ::core::convert::From for v1beta1::Foo { @@ -33,10 +41,32 @@ impl ::core::convert::From for v1alpha2::Foo { } } #[automatically_derived] +impl ::core::convert::From for v1beta1::Mode { + fn from(__sv_mode: v1alpha2::Mode) -> Self { + match __sv_mode { + v1alpha2::Mode::A => v1beta1::Mode::A, + v1alpha2::Mode::B => v1beta1::Mode::B, + } + } +} +#[automatically_derived] +impl ::core::convert::From for v1alpha2::Mode { + fn from(__sv_mode: v1beta1::Mode) -> Self { + match __sv_mode { + v1beta1::Mode::A => v1alpha2::Mode::A, + v1beta1::Mode::B => v1alpha2::Mode::B, + } + } +} +#[automatically_derived] mod v1beta1 { use super::*; pub struct Foo { pub baz: usize, pub qux: String, } + pub enum Mode { + A, + B, + } } diff --git a/crates/stackable-versioned/CHANGELOG.md b/crates/stackable-versioned/CHANGELOG.md index 42b23205a..d6ffb8e0b 100644 --- a/crates/stackable-versioned/CHANGELOG.md +++ b/crates/stackable-versioned/CHANGELOG.md @@ -22,10 +22,11 @@ All notable changes to this project will be documented in this file. strings ([#1326]). - The generated tracking status now respects the `schemars` and `serde` crate overrides. Previously, it failed to compile if these crates were not direct dependencies ([#1326]). -- Structs now respect the version-level `skip(from)` flag, e.g. `version(name = "v1alpha1", skip(from))`. +- BREAKING: Structs now respect the version-level `skip(from)` flag, e.g. `version(name = "v1alpha1", skip(from))`. Previously, only enums respected it, so the `From` impls between the flagged and the next version were still generated for structs, which conflicted with manual implementations. Likewise, enums now - respect the module-level `skip(from)` flag ([#1344]). + respect the module-level `skip(from)` flag. Code which relied on the previously generated impls now + needs to implement them manually ([#1344]). [#1324]: https://github.com/stackabletech/operator-rs/pull/1324 [#1325]: https://github.com/stackabletech/operator-rs/pull/1325