-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
crates/stackable-versioned-macros/src/codegen/container/struct/k8s.rs
Outdated
Show resolved
Hide resolved
crates/stackable-versioned-macros/src/codegen/container/struct/k8s.rs
Outdated
Show resolved
Hide resolved
…/k8s.rs Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
} | ||
|
||
#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> { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
crates/stackable-versioned-macros/src/codegen/container/struct/k8s.rs
Outdated
Show resolved
Hide resolved
crates/stackable-versioned-macros/src/codegen/container/struct/k8s.rs
Outdated
Show resolved
Hide resolved
crates/stackable-versioned-macros/src/codegen/container/struct/k8s.rs
Outdated
Show resolved
Hide resolved
crates/stackable-versioned-macros/src/codegen/container/struct/k8s.rs
Outdated
Show resolved
Hide resolved
|
||
#[cfg(test)] | ||
mod tests; |
There was a problem hiding this comment.
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").
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved in 8f77619
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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) | ||
} |
There was a problem hiding this comment.
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
.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…/k8s.rs Co-authored-by: Techassi <git@techassi.dev>
…/k8s.rs Co-authored-by: Techassi <git@techassi.dev>
Co-authored-by: Techassi <git@techassi.dev>
Co-authored-by: Techassi <git@techassi.dev>
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
test.stackable.tech/v1alpha1
as apiVersion, notv1alpha1
PS: The diff is so big because lots of tests (snapshots) changed. Actual code change is only a small portion.
Definition of Done Checklist
Author
Reviewer
Acceptance