feat(stackable-versioned)!: Integrate with ConversionReviews#1050
Merged
feat(stackable-versioned)!: Integrate with ConversionReviews#1050
Conversation
sbernauer
commented
Jun 2, 2025
crates/stackable-versioned-macros/src/codegen/flux_converter.rs
Outdated
Show resolved
Hide resolved
76 tasks
These tests are removed for now, because we are not able to roundtrip CRD conversions without data loss yet. This feature will be re-added in a follow-up PR in an improved form once loss-less roundtripping is supported.
Member
NickLarsenNZ
left a comment
There was a problem hiding this comment.
Left comments and suggestions
| @@ -1,5 +1,6 @@ | |||
| { | |||
| "rust-analyzer.cargo.features": "all", | |||
| "rust-analyzer.imports.granularity.group": "crate", | |||
Member
There was a problem hiding this comment.
Note to self: check if this is the same in our other rust repos:
- operator-templating
- stackablectl
- docker-images (patchable)
- containerdebug
- actions (interu)
- trino-lb
- product-config (any reason this can't just be a crate inside operator-rs?)
- config-utils
There are more, but they are less used.
Member
There was a problem hiding this comment.
Nothing to action here, this was just me thinking. I will check it out later.
Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds utilities to convert a CRD from one version into a different version. This is tightly integrated with CRD conversions, which send
ConversionReviews to registered webhooks and return that review to the K8s apiserver.TLDR
#[versioned(k8s(skip(merged_crd)))]flag has been removedmerged_crdis now suffixed withVersiontry_convertfunction to convert objects received via a ConversionReviewenable_tracingoption to#[versioned(k8s(options(...)))]Detailed Overview
There are multiple different parts to make this whole process work. All of these parts are automatically generated by the macro and for the user it is a single function call:
Foo::try_convert. The individual parts are explained below.Note
The CRD spec currently does not contain any fields. During the development of the conversion mechanism, this is emitted to more easily focus on the newly generated code. It will eventually contain fields to fully test the implementation.
Updated Version Enum
The generated code tries to abstract away as much of the underlying code as possible. For this use-case, a top-level version enum exists. Before this PR, it only provided an easy way to produce a single, merged CRD based on all defined CRD versions via
Foo::merged_crd(Foo::V1). The variants described the available versions and forced users to use well-defined versions instead of&strwhich can be anything (eg. an invalid version).This PR changes the inner workings of this enum. Instead of only providing plain variants without any data, each variant now holds the appropriate version of the custom resource.
This change enables us to directly deserialize an object of a custom resource into the enum. This then enables us to generate further (in addition to
merged_crd) top-level abstractions on the enum.With this change it is not possible to use
Selfto specify the stored apiversion viaFoo::merged_crd(). Instead, a new enum for this purpose only is generated.(De)serialization from/to JSON values
Most (if not all) conversion will be handled automatically by a CRD conversion webhook. Before the K8s apiserver either stores the custom resource in etcd or responds to clients, it will send a
ConversionReviewto the registered webhook. A list of to be converted objects is provided as a JSON object. This is also represented in Rust code, more specifically aserde_json::Value.As such, the code needs to be able to turn the JSON object into a Rust representation (in the correct version). Once conversion is performed, the opposite operation needs to be performed: turning the Rust struct back into serialized JSON.
This PR introduces two new (private) methods to do this:
Conversion function
Currently, conversion of custom objects (defined by versioned CRDs) is achieved by receiving the ConversionReview via a webhook (which will be run alongside the operator in the future). This ConversionReview is then handed over to the
try_convertfunction. Internally, this will construct strictly typed objects based on the current apiVersion. They are then converted to the desired apiVersion and added to the list of converted objects. If all objects were able to be converted, a successful ConversionReview is returned. Otherwise, a failure is indicated....
Partial expanded code