fix: Produce valid CRDs containing flattened untagged enums#1942
Conversation
8f9df35 to
18bf1ea
Compare
Note: This comes from kube-rs#1839, with some modifications (an extra field to the B variant, and change comments to indicate untagged variant descriptions should not leak into fields). Co-authored-by: Sebastian Bernauer <sebastian.bernauer@stackable.tech> Signed-off-by: Nick Larsen <nick.larsen@stackable.tech>
…iants without fields Signed-off-by: Nick Larsen <nick.larsen@stackable.tech>
… for oneOf Note: variant descriptions are meaningless for untagged enums - they don't correspond to the fields inside struct variants. Signed-off-by: Nick Larsen <nick.larsen@stackable.tech>
18bf1ea to
596bb93
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1942 +/- ##
=======================================
+ Coverage 76.2% 76.3% +0.1%
=======================================
Files 89 89
Lines 8487 8495 +8
=======================================
+ Hits 6465 6474 +9
+ Misses 2022 2021 -1
🚀 New features to boost your workflow:
|
doxxx93
left a comment
There was a problem hiding this comment.
Verified with a kind cluster:
- The original bug reproduces on
main(anyOf[2].description: Forbidden,anyOf[2].type: Forbidden) - With this fix, CRD registration and CR instance creation all pass (tested struct variants, empty variants, newtype variants,
Option<>,Vec<>, nested untagged enums) - No regression on tagged enums (
oneOf)
One minor nit left inline about test coverage for a newtype variant hitting the same else if branch.
LGTM otherwise.
|
Sorry for the ping @clux — I've verified the normal behavior through the tests. One thing I noticed: the new else if branch (removing type/metadata from variants without fields) runs for both one_of (tagged) and any_of (untagged) paths, even though the comment says "untagged variants." Is this fine? Could you take a look when you get a chance? |
No this isn't fine. I will fix that (by only doing it when I didn't see any test failing. Can you share how you tested that? |
|
@NickLarsenNZ I didn't find a specific failing test case — it was more of a code review observation that the else if branch could theoretically run in the one_of (tagged) path as well. The existing tests with tagged enums pass fine, but I wasn't confident there isn't an uncovered edge case. |
|
@doxxx93 I see what you mean. These extra fields need to go regardless of oneOf or anyOf, as they are not accepted by Kubernetes. My original implementation does this (and only preserves the descriptions in the case of a oneOf by moving them into the applicable property). I would keep it as-is for now, and raise a separate refactor PR based on the properties hoisting in #1839 which is easier to test/debug IMO - if you're ok with that. |
| subschemas: &mut Vec<Schema>, | ||
| common_obj: &mut Option<Box<ObjectValidation>>, | ||
| instance_type: &mut Option<SingleOrVec<InstanceType>>, | ||
| push_description_to_property: bool, |
There was a problem hiding this comment.
this signature is getting a little awkard and is probably another refactoring candidate for refactoring later.
There was a problem hiding this comment.
Yes, this was properly handled in the original refactor: https://github.com/stackabletech/kube-rs/blob/71707abf1109bad01bbf2c46e3b161846049767a/kube-core/src/schema/transform_properties.rs#L50-L57
Signed-off-by: Nick Larsen <nick.larsen@stackable.tech>
|
Thank you! |
Fixes #1941
Note
This is a minimal fix to make review easier and close the issue.
A follow up PR is intended to replace the properties transformation into a proper transformer like in #1839.
descriptionandtypefields are dropped on untagged variants without fields.