Skip to content
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

Minor fixes to ObjectList #1398

Merged
merged 3 commits into from
Jan 26, 2024
Merged

Minor fixes to ObjectList #1398

merged 3 commits into from
Jan 26, 2024

Conversation

flavio
Copy link
Contributor

@flavio flavio commented Jan 25, 2024

Motivation

Starting from the 0.88.0 release, ObjectList has a new attribute named types. This attribute is serialized and deserialized using the flatten directive of serde.

However, it turns out that serde has a bug that prevents the proper deserialization of attributes that are using the flatten and default directives. See here and here.

This serde bug affects the freshly introduced ObjectList.types attribute. It's not possible to deserialize an ObjectList that is missing the apiVersion and/or the kind values.

Solution

This commit introduces a custom deserializer for the types attribute of ObjectList that solves this problem.

On top of handling the deserialization case, the custom deserializer provides better default values compared to the ones of the stock TypeMeta.
The TypeMeta struct has empty strings as default values. However, in the context of ObjectList, proper default values should be v1 and List instead.

There's also a second commit to this PR that makes ObjectList derive the Clone trait. This is not related with this specific issue, but is something that some code I've written would take advantage of. If you're not fine with this specific commit I can drop it from this PR.

…tion

The `serde` crate has a bug that prevents the proper deserialization of
attributes that are using the `flatten` and `default` directives.
See [1] and [2].

This bug affects the freshly introduced `ObjectList.types` attribute.
It's not possible to deserialize an `ObjectList` that is missing the
`apiVersion` and/or the `kind` values.

This commit introduces a custom deserializer for the `types` attribute
of `ObjectList`.

On top of handling the deserialization case, the custom deserializer
provides better default values compared to the ones of the stock
`TypeMeta`.
The `TypeMeta` struct has empty strings as default values. However, in the
context of `ObjectList`, proper default values should be `v1` and `List`
instead.

[1] serde-rs/serde#1626
[2] serde-rs/serde#1879

Signed-off-by: Flavio Castelli <[email protected]>
Ensure `ObjectList` derive the `Clone` trait.

Signed-off-by: Flavio Castelli <[email protected]>
Copy link
Member

@clux clux left a comment

Choose a reason for hiding this comment

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

Ah, damn. Sorry about this, but thanks a lot for coming up with such a clean fix!

This all looks good to me. Happy to merge and do a patch release when CI is green.

@clux clux added the changelog-fix changelog fix category for prs label Jan 25, 2024
@clux clux added this to the 0.88.1 milestone Jan 25, 2024
Copy link

codecov bot commented Jan 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2ad41b2) 72.1% compared to head (7684dda) 72.1%.

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1398     +/-   ##
=======================================
+ Coverage   72.1%   72.1%   +0.1%     
=======================================
  Files         75      75             
  Lines       6458    6470     +12     
=======================================
+ Hits        4651    4663     +12     
  Misses      1807    1807             
Files Coverage Δ
kube-core/src/object.rs 86.1% <100.0%> (+2.1%) ⬆️

Signed-off-by: Flavio Castelli <[email protected]>
@flavio
Copy link
Contributor Author

flavio commented Jan 25, 2024

@clux thanks for the review. I've pushed a commit that fixes the rustfmt issue

@clux clux merged commit b700529 into kube-rs:main Jan 26, 2024
17 checks passed
@clux
Copy link
Member

clux commented Jan 26, 2024

Thanks! Released in 0.88.1

@flavio flavio deleted the objectlist-fixes branch January 26, 2024 07:36
flavio added a commit to flavio/kwctl that referenced this pull request Jan 29, 2024
kube 0.88.0 introduced a minor regression: kube-rs/kube#1398

That caused kwctl 1.10.0 to fail while running e2e tests under specific circumstances.
Replaying a host capabilities sessions recorded with an older version of kwctl
would cause Rego policies to fail. waPC policies would not fail.

This patch release of kwctl addresses this specific regression.

Signed-off-by: Flavio Castelli <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-fix changelog fix category for prs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants