Skip to content

fix(stackable-versioned): Fix bugs in ConversionReviews integration #1061

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 28 commits into
base: main
Choose a base branch
from

Conversation

sbernauer
Copy link
Member

@sbernauer sbernauer commented Jun 23, 2025

Motivation

#1056 will also fix at least some of the bugs, but I would prefer to fix the bugs fast and have tests.
I'm happy that my code gets overwritten by #1056 as longs as the tests pass.
By fixing the problems we can continue on working an the actual conversion HTTPS webhook stuff.

Description

Fix some problems in the (brand new) conversions. And most important: Re-add tests that temporarily have been removed from #1050

  • check if we know about the desired version, error if not. Previously we would noop for unknown desired versions.
  • k8s sends us test.stackable.tech/v1alpha1 as apiVersion, not v1alpha1
  • Check that the sent k8s kind is the one we expect

PS: The diff is so big because lots of tests (snapshots) changed. Actual code change is only a small portion.

Definition of Done Checklist

  • Not all of these items are applicable to all PRs, the author should update this template to only leave the boxes in that are relevant
  • Please make sure all these things are done and tick the boxes

Author

  • Changes are OpenShift compatible
  • CRD changes approved
  • CRD documentation for all fields, following the style guide.
  • Integration tests passed (for non trivial changes)
  • Changes need to be "offline" compatible

Reviewer

  • Code contains useful comments
  • Code contains useful logging statements
  • (Integration-)Test cases added
  • Documentation added or updated. Follows the style guide.
  • Changelog updated
  • Cargo.toml only contains references to git tags (not specific commits or branches)

Acceptance

  • Feature Tracker has been updated
  • Proper release label has been added

@sbernauer sbernauer changed the title fix(stackable-versioned): Fix multiple bugs in ConversionReviews integration fix(stackable-versioned): Fix bugs in ConversionReviews integration Jun 23, 2025
@sbernauer sbernauer moved this to Development: Waiting for Review in Stackable Engineering Jun 23, 2025
NickLarsenNZ
NickLarsenNZ previously approved these changes Jun 23, 2025
Copy link
Member

@NickLarsenNZ NickLarsenNZ left a comment

Choose a reason for hiding this comment

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

Just a couple of suggestions so far

…/k8s.rs

Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
@sbernauer sbernauer requested a review from NickLarsenNZ June 24, 2025 07:13
@sbernauer sbernauer moved this from Development: Waiting for Review to Development: In Review in Stackable Engineering Jun 24, 2025
}

#convert_method

fn from_json_value(value: #serde_json_path::Value) -> ::std::result::Result<Self, #parse_object_error> {
let api_version = value
fn from_json_value(object: #serde_json_path::Value) -> ::std::result::Result<Self, #parse_object_error> {
Copy link
Member

Choose a reason for hiding this comment

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

note: I think we should stick with the parameter name value here. In my mind, this can only be called an object after it has been parsed as such. Also, the function name suggests that this parameter should be called value.

Copy link
Member Author

@sbernauer sbernauer Jun 24, 2025

Choose a reason for hiding this comment

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

I already had all of this thoughts and though about renaming the function to smh like `try_from_json_object) but didn't want to get into bikeshedding. But here we are :)

This function expects you to pass a k8s object to it, not an arbitrary JSON value such as f32 or String. I think we should make this clear in the name, I would therefore propose to name it fn try_from_json_object(object: #serde_json_path::Value) or fn try_from_json_k8s_object(k8s_object: #serde_json_path::Value) (the try_ prefix is already under discussion in #1061 (comment))

Copy link
Member

@Techassi Techassi Jun 24, 2025

Choose a reason for hiding this comment

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

I would be fine with fn try_from_json_object(object_value: #serde_json_path::Value) and internally clearly separate between the "raw" object and the successfully deserialized "object" we return in the end.

In my opinion the try_ prefix doesn't provide a whole lot here. The function clearly indicates that it is fallible by returning a Result.

Copy link
Member Author

Choose a reason for hiding this comment

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

That sounds like a good compromise! 119a845

Comment on lines 20 to 22

#[cfg(test)]
mod tests;
Copy link
Member

Choose a reason for hiding this comment

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

note: I would like to avoid this. Instead, we want automatic support for integration tests by moving the "tests" folder one layer up (out of "src").

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved in 8f77619

Copy link
Member

Choose a reason for hiding this comment

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

suggestion: I would additionally drop the fixtures part from the folder structure. Then we have the same structure as in stackable-versioned-macros.

suggestion: I would also rename the tests/integration_test.rs file to tests/conversion.rs because we are testing the conversion. There might be other kind of integration tests in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

works for me

7400d39 now has files such as crates/stackable-versioned/tests/inputs/conversions/fail/wrong_kind.json

Comment on lines 132 to 139
fn run_for_file(path: &Path) -> (ConversionReview, ConversionReview) {
let request: ConversionReview =
serde_json::from_reader(File::open(path).expect("failed to open test file"))
.expect("failed to parse ConversionReview from test file");
let response = Person::try_convert(request.clone());

(request, response)
}
Copy link
Member

Choose a reason for hiding this comment

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

note: Similar to stackable-versioned-macros, I would like this function to live in a test_utils module (which is gated behind #[cfg(test)].

I suggest to adjust the name to better indicate what this function does and adding a dedicated error enum similar to expand_from_file.

Suggested change
fn run_for_file(path: &Path) -> (ConversionReview, ConversionReview) {
let request: ConversionReview =
serde_json::from_reader(File::open(path).expect("failed to open test file"))
.expect("failed to parse ConversionReview from test file");
let response = Person::try_convert(request.clone());
(request, response)
}
fn convert_via_file(path: &Path) -> (ConversionReview, ConversionReview) {
let request: ConversionReview =
serde_json::from_reader(File::open(path).expect("failed to open test file"))
.expect("failed to parse ConversionReview from test file");
let response = Person::try_convert(request.clone());
(request, response)
}

Ideally, this function would be generic over the kind we want to convert. This is however currently not possible but worth a thought in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried putting it in crates/stackable-versioned/src/test_utils.rs, the problem is that we don't know Person in there...
And currently we don't have a trait for the T::try_convert(request.clone()) function. So I'm missing how we can move the convert_via_file function

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed in b7080ac

// NOTE (@Techassi): I'm curious if this will ever happen? In theory the K8s
// apiserver should never send such a conversion review.
_ => converted_objects.push(object),
match (current_object, &desired_api_version) {
Copy link
Member

Choose a reason for hiding this comment

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

note: Using a reference here seems a little weird. We could instead add #[derive(Copy, Clone)] to the version enum, to be able to cheaply copy the enum, which is also suggested by the docs.

Would be interesting to see if there are any performance differences. This StackOverflow post seems to suggest that copying is smaller in memory but there will be likely no performance difference.

Copy link
Member Author

Choose a reason for hiding this comment

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

@sbernauer sbernauer requested a review from Techassi June 24, 2025 13:35
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.

3 participants