Skip to content

feat(stackable-versioned)!: Add conversion tracking #1056

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 37 commits into from
Jul 10, 2025

Conversation

Techassi
Copy link
Member

@Techassi Techassi commented Jun 13, 2025

Part of stackabletech/issues#642

Caution

It should be noted, that only simple additions of fields can be tracked across conversions. Complex action combinations and other types of changes cannot be tracked. Support for this will be added in the future.

Summary

  • BREAKING: The macro can only be applied to modules now.
  • BREAKING: Crate overrides are now done at the module level, not the container level.
  • BREAKING: Top-level CRD specs now use crd(...) instead of k8s(...).
  • BREAKING: The (optional) status needs to implement Default.
  • The conversion tracking is behind the experimental_conversion_tracking flag.
  • A new nested flag was added to mark individual fields as nested (indicating that the sub struct also contains changes which need to be tracked).
#[versioned(
    version(name = "v1alpha1"),
    version(name = "v1alpha2"),
    version(name = "v1beta1"),
    version(name = "v2"),
    version(name = "v3"),
    options(k8s(experimental_conversion_tracking))
)]
pub mod versioned {
    #[versioned(crd(group = "test.stackable.tech", status = "PersonStatus"))]
    #[derive(Clone, Debug, CustomResource, Deserialize, JsonSchema, Serialize)]
    #[serde(rename_all = "camelCase")]
    pub struct PersonSpec {
        username: String,

        // In v1alpha2 first and last name have been added
        #[versioned(added(since = "v1alpha2"))]
        first_name: String,

        #[versioned(added(since = "v1alpha2"))]
        last_name: String,

        // We started out with a enum. As we *need* to provide a default, we have a Unknown variant.
        // Afterwards we figured let's be more flexible and accept any arbitrary String.
        #[versioned(added(since = "v2"), changed(since = "v3", from_type = "Gender"))]
        gender: String,

        #[versioned(nested)]
        socials: Socials,
    }

    // Ideally, we want this to be versioned independently from the CRD spec above. The addition
    // of the `mastodon` field would then require a change on the `socials` field above. But as
    // mentioned, currently we don't support individual versions nor complex action + nested
    // combinations.
    // This still demonstrates that tracking works in nested sub structs on a basic level (for now).
    #[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
    pub struct Socials {
        email: String,

        #[versioned(added(since = "v1beta1"))]
        mastodon: String,
    }
}

#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct PersonStatus {
    pub alive: bool,
}

Learnings from this PR

  • We need per-container versions. The current mechanism doesn't make sense for more complex CRDs with multiple sub structs (at different versions).
  • We need fallible conversions.
  • We need to support to track other types of changes to be able to use this on real CRDs.
  • We need to integrate with Serde (for renames, flattening, untagged).

@Techassi Techassi self-assigned this Jun 13, 2025
@Techassi Techassi moved this to Development: In Progress in Stackable Engineering Jun 13, 2025
@Techassi Techassi force-pushed the feat/stackable-versioned-conversion-tracking branch from 46acd20 to 3ec678e Compare June 17, 2025 11:19
@Techassi Techassi force-pushed the feat/stackable-versioned-conversion-tracking branch from a72df96 to 7411abd Compare July 2, 2025 14:26
@Techassi Techassi force-pushed the feat/stackable-versioned-conversion-tracking branch from 7411abd to 4009271 Compare July 2, 2025 15:07
sbernauer
sbernauer previously approved these changes Jul 9, 2025
Copy link
Member

@sbernauer sbernauer left a comment

Choose a reason for hiding this comment

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

LGTM % remaining comment and conflicts

@Techassi Techassi requested a review from sbernauer July 9, 2025 14:19
sbernauer
sbernauer previously approved these changes Jul 9, 2025
Copy link
Member

@sbernauer sbernauer left a comment

Choose a reason for hiding this comment

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

LGTM but we have test failures

@Techassi
Copy link
Member Author

Techassi commented Jul 9, 2025

Ah! This was allowed previously. I will update the test.

sbernauer
sbernauer previously approved these changes Jul 10, 2025
@Techassi Techassi added this pull request to the merge queue Jul 10, 2025
@sbernauer sbernauer moved this from Development: In Review to Development: Done in Stackable Engineering Jul 10, 2025
@Techassi Techassi removed this pull request from the merge queue due to a manual request Jul 10, 2025
@Techassi Techassi changed the title feat(stackable-versioned): Add conversion tracking feat(stackable-versioned)!: Add conversion tracking Jul 10, 2025
@Techassi Techassi added this pull request to the merge queue Jul 10, 2025
Merged via the queue into main with commit 4ca1c0d Jul 10, 2025
8 checks passed
@Techassi Techassi deleted the feat/stackable-versioned-conversion-tracking branch July 10, 2025 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Development: Done
Development

Successfully merging this pull request may close these issues.

3 participants