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

Support top-level enums in CRDs #856

Merged
merged 4 commits into from
Mar 24, 2022

Conversation

sbernauer
Copy link
Contributor

Currently only top-level structs are supported. Enums are supported as well (with some limitations) but not at top-level.

Motivation

I want to specify a CRD with a top-level enum

Solution

Added support for top-level enums

Signed-off-by: Sebastian Bernauer <sebastian.bernauer@stackable.de>
@sbernauer sbernauer force-pushed the feature/top-level-enum branch from 675a5fb to ed8f12b Compare March 23, 2022 13:51
@codecov-commenter
Copy link

codecov-commenter commented Mar 23, 2022

Codecov Report

Merging #856 (8805251) into master (116a970) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #856   +/-   ##
=======================================
  Coverage   70.56%   70.57%           
=======================================
  Files          59       61    +2     
  Lines        4212     4244   +32     
=======================================
+ Hits         2972     2995   +23     
- Misses       1240     1249    +9     
Impacted Files Coverage Δ
kube-derive/src/custom_resource.rs 12.80% <ø> (ø)
kube-derive/tests/crd_enum_test.rs 100.00% <100.00%> (ø)
kube-client/src/client/mod.rs 68.15% <0.00%> (-2.11%) ⬇️
kube-runtime/src/wait.rs 68.00% <0.00%> (-2.00%) ⬇️
kube-derive/tests/crd_schema_test.rs 100.00% <0.00%> (ø)
kube-client/src/client/builder.rs 71.92% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 116a970...8805251. Read the comment docs.

Copy link
Member

@nightkr nightkr left a comment

Choose a reason for hiding this comment

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

I'm not sure I'd encourage anyone to actually use this, but I also can't really justify forbidding it entirely.

@sbernauer
Copy link
Contributor Author

I'm a little bit surprised, what are the disadvantages that you see when using a top-level enum?

@nightkr
Copy link
Member

nightkr commented Mar 23, 2022

I'd guesstimate that most CRDs will have at least some fields that are common between variants, and using enums will make it harder to transition to those later. You could do something like:

struct FooKind {
    shared: String,
    #[serde(flatten)]
    method: FooKindMethod,
}

enum FooKindMethod {
    Foo { ... },
    Bar { ... },
}

But that feels like it would get clunky and unclear to document which fields are mutually exclusive with which.

@clux
Copy link
Member

clux commented Mar 23, 2022

as an addendum to what Teo is saying:

It's a funny thing about the versioning of kubernetes crds that most people are almost never bumping the apiVersion and instead keep making tiny-non-breaking changes to it (adding new options, merely marking fields as deprecated) until some major release. Enums make that slightly harder. But I don't see any other reasons why you would want to be careful with such a spec.

@clux clux added the changelog-add changelog added category for prs label Mar 23, 2022
@clux clux added this to the 0.71.0 milestone Mar 23, 2022
@sbernauer
Copy link
Contributor Author

Thanks for your feedback!
I'm with you that the usage of a top-level Enum must thought through but can also think of some cases where it is useful.

@clux
Copy link
Member

clux commented Mar 23, 2022

Agreed. Edge-case, but has potential.

CI wise, I think github was struggling earlier, so it looks like you might need to push again or do the DCO thing (the action has details).

Signed-off-by: Sebastian Bernauer <sebastian.bernauer@stackable.de>
@sbernauer sbernauer force-pushed the feature/top-level-enum branch from a64014e to c6d1b6a Compare March 24, 2022 07:09
Signed-off-by: Sebastian Bernauer <sebastian.bernauer@stackable.de>
@sbernauer sbernauer force-pushed the feature/top-level-enum branch from 622c009 to 8805251 Compare March 24, 2022 07:25
@sbernauer
Copy link
Contributor Author

There is something strange going in the clippy check. cargo +nightly clippy works for me locally.
I'm trying to look into it.

Signed-off-by: Sebastian Bernauer <sebastian.bernauer@stackable.de>
@sbernauer
Copy link
Contributor Author

Checks are blocked by briansmith/ring#1469

@clux
Copy link
Member

clux commented Mar 24, 2022

Oh, ok, whatever. We can fix-forward on clippy. I'l just merge this now that DCO and all important checks are green.

@clux clux merged commit 188205c into kube-rs:master Mar 24, 2022
@sbernauer
Copy link
Contributor Author

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-add changelog added category for prs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants