Skip to content

Commit 8eea0ad

Browse files
authored
fix(stackable-versioned): Correctly emit #[kube(status = ...)] attribute (#1046)
* fix(stackable-versioned): Correctly emit kube status attribute * chore(stackable-versioned): Add changelog entry
1 parent 077302c commit 8eea0ad

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

crates/stackable-versioned-macros/src/codegen/container/struct.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,18 +348,24 @@ impl Struct {
348348
.then_some(quote! { , namespaced });
349349
let crates = kubernetes_options.crates.to_token_stream();
350350

351-
// TODO (@Techassi): This struct name should be defined once in a single place instead
352-
// of constructing it in two different places which can lead to de-synchronization.
353-
let status = kubernetes_options
354-
.config_options
355-
.experimental_conversion_tracking
356-
.then(|| {
351+
let status = match (
352+
kubernetes_options
353+
.config_options
354+
.experimental_conversion_tracking,
355+
&kubernetes_options.status,
356+
) {
357+
(true, _) => {
358+
// TODO (@Techassi): This struct name should be defined once in a single place instead
359+
// of constructing it in two different places which can lead to de-synchronization.
357360
let status_ident = format_ident!(
358361
"{struct_ident}StatusWithChangedValues",
359362
struct_ident = self.common.idents.kubernetes.as_ident()
360363
);
361-
quote! { , status = #status_ident }
362-
});
364+
Some(quote! { , status = #status_ident })
365+
}
366+
(_, Some(status_ident)) => Some(quote! { , status = #status_ident }),
367+
(_, _) => None,
368+
};
363369

364370
let shortnames: TokenStream = kubernetes_options
365371
.shortnames

crates/stackable-versioned-macros/tests/inputs/k8s/pass/basic.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use stackable_versioned::versioned;
88
group = "stackable.tech",
99
singular = "foo",
1010
plural = "foos",
11+
status = FooStatus,
1112
namespaced,
1213
)
1314
)]
@@ -26,6 +27,11 @@ pub(crate) struct FooSpec {
2627
// ---
2728
fn main() {}
2829

30+
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
31+
pub struct FooStatus {
32+
is_foo: bool,
33+
}
34+
2935
fn usize_to_u16(input: usize) -> u16 {
3036
input.try_into().unwrap()
3137
}

crates/stackable-versioned-macros/tests/snapshots/stackable_versioned_macros__snapshot_tests__k8s@basic.rs.snap

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

crates/stackable-versioned/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ All notable changes to this project will be documented in this file.
2626

2727
### Fixed
2828

29+
- Fix regression introduced in [#1033]. The `#[kube(status = ...)]` attribute is generated correctly
30+
again ([#1046]).
2931
- Correctly handle fields added in later versions ([#1031]).
3032

3133
### Removed
@@ -41,6 +43,7 @@ All notable changes to this project will be documented in this file.
4143
[#1033]: https://github.com/stackabletech/operator-rs/pull/1033
4244
[#1038]: https://github.com/stackabletech/operator-rs/pull/1038
4345
[#1041]: https://github.com/stackabletech/operator-rs/pull/1041
46+
[#1046]: https://github.com/stackabletech/operator-rs/pull/1046
4447

4548
## [0.7.1] - 2025-04-02
4649

0 commit comments

Comments
 (0)