Skip to content

feat(stackable-versioned): Generate downgrade From impls #1033

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Techassi
Copy link
Member

@Techassi Techassi commented May 14, 2025

This PR adds support to downgrade CRDs.

  • The #[versioned()] macro generates From impls for downgrading.
  • Change the convert_with parameter of the changed() action accordingly to support customizing both the upgrade and downgrade conversion function. There are now two separate parameters: upgrade_with and downgrade_with.
  • Emit a status subresource to be able to track values of the resource during upgrade and downgrade operations.

@Techassi Techassi self-assigned this May 14, 2025
@Techassi Techassi force-pushed the feat/stackable-versioned-downgrade-from-impls branch from 53fe2c7 to 3fc0b82 Compare May 16, 2025 10:28
@Techassi Techassi moved this to Development: In Progress in Stackable Engineering May 16, 2025
@Techassi Techassi moved this from Development: In Progress to Development: Waiting for Review in Stackable Engineering May 16, 2025
@Techassi Techassi marked this pull request as ready for review May 16, 2025 10:36

k8s-openapi.workspace = true
kube.workspace = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Check if this is needed

@@ -240,13 +240,13 @@ impl CommonItemAttributes {

// The convert_with argument only makes sense to use when the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The convert_with argument only makes sense to use when the
// The upgrade_with argument only makes sense to use when the

@@ -240,13 +240,13 @@ impl CommonItemAttributes {

// The convert_with argument only makes sense to use when the
// type changed
if let Some(convert_func) = change.convert_with.as_ref() {
if let Some(upgrade_func) = change.upgrade_with.as_ref() {
if change.from_type.is_none() {
errors.push(
Error::custom(
"the `convert_with` argument must be used in combination with `from_type`",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"the `convert_with` argument must be used in combination with `from_type`",
"the `upgrade_with` argument must be used in combination with `from_type`",

@@ -240,13 +240,13 @@ impl CommonItemAttributes {

// The convert_with argument only makes sense to use when the
// type changed
if let Some(convert_func) = change.convert_with.as_ref() {
if let Some(upgrade_func) = change.upgrade_with.as_ref() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need the same code block for downgrade pls

)]
#[serde(rename_all = "camelCase")]
pub struct #status_ident {
pub crd_values: #versioned_crate::CrdValues,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Think about a better name

pub status: #status,
}
}),
None => Some(quote! {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should combine the variants and only conditionally have

                            #[serde(flatten)]
                            pub status: #status,

@@ -391,4 +465,52 @@ impl Struct {
_ => None,
}
}

pub fn generate_kubernetes_status_struct(&self) -> Option<TokenStream> {
match &self.common.options.kubernetes_options {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let kubernetes_options = self.common.options.kubernetes_options.as_ref()?; instead pls

Comment on lines +359 to +365
let status = if multiple_versions {
let status_ident = format_ident!(
"{struct_ident}Status",
struct_ident = self.common.idents.kubernetes.as_ident()
);
Some(quote! { , status = #status_ident })
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to either wait with the merge until the Status structure is proven to be working or comment this code out or put it behind an opt-in

@sbernauer sbernauer moved this from Development: Waiting for Review to Development: In Review in Stackable Engineering May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Development: In Review
Development

Successfully merging this pull request may close these issues.

2 participants