Skip to content

fix(stackable-versioned): Correctly emit #[kube(status = ...)] attribute #1046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 14 additions & 8 deletions crates/stackable-versioned-macros/src/codegen/container/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,24 @@ impl Struct {
.then_some(quote! { , namespaced });
let crates = kubernetes_options.crates.to_token_stream();

// TODO (@Techassi): This struct name should be defined once in a single place instead
// of constructing it in two different places which can lead to de-synchronization.
let status = kubernetes_options
.config_options
.experimental_conversion_tracking
.then(|| {
let status = match (
kubernetes_options
.config_options
.experimental_conversion_tracking,
&kubernetes_options.status,
) {
(true, _) => {
// TODO (@Techassi): This struct name should be defined once in a single place instead
// of constructing it in two different places which can lead to de-synchronization.
let status_ident = format_ident!(
"{struct_ident}StatusWithChangedValues",
struct_ident = self.common.idents.kubernetes.as_ident()
);
quote! { , status = #status_ident }
});
Some(quote! { , status = #status_ident })
}
(_, Some(status_ident)) => Some(quote! { , status = #status_ident }),
(_, _) => None,
};

let shortnames: TokenStream = kubernetes_options
.shortnames
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use stackable_versioned::versioned;
group = "stackable.tech",
singular = "foo",
plural = "foos",
status = FooStatus,
namespaced,
)
)]
Expand All @@ -26,6 +27,11 @@ pub(crate) struct FooSpec {
// ---
fn main() {}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
pub struct FooStatus {
is_foo: bool,
}

fn usize_to_u16(input: usize) -> u16 {
input.try_into().unwrap()
}

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

3 changes: 3 additions & 0 deletions crates/stackable-versioned/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ All notable changes to this project will be documented in this file.

### Fixed

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

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

## [0.7.1] - 2025-04-02

Expand Down
Loading