-
Notifications
You must be signed in to change notification settings - Fork 502
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
Update documentation for use of kubebuilder Enum tags #1014
Comments
Here's some relevant quotes from the core docs:
I'm not wedded to removing all enums, just want us to have talked about it before we go to |
IIUC "do not use enums" refers to code like this: const (
Foo = iota
Bar
Baz
)
It sounds like this would apply if the API uses any enum strings in status, which is context-dependent. The other subtley in my reading of this is "If an API drives behavior that is implemented by external clients", which implies that a one controller sets the value and some other controller observes and responds to that change. |
Removing a value (rather than just deprecating in place) makes sense as a breaking change, but I'm a little unclear on how adding a value (to the end, not reordering), would be much worse than adding a new value for an aliased string type? In both cases I'd expect a client would need to handle unexpected values safely or risk unexpected behavior/panics - is it just that there's a greater expectation for enums that matching is always exhaustive and a catch-all won't ever be needed if all currently-known states are handled? I think it might be helpful to see a side-by-side example of a current enum field versus what the proposed alternative might look like. (My understanding is that enums are fine for internal handling of values, just discouraged as enums in a public API?) |
Thanks for catching this @youngnick! I agree that even adding an allowed value to an enum could be considered a breaking change if we hadn't prepared users/implementers for that possibility. Your quote from the conventions seems very relevant here:
It seems very straightforward to add text along with each of our enums that indicates that additional values may be allowed in the future. The second part is less clear. If, for example, an implementation runs into a match type that it doesn't recognize, what should it do? Should it drop/ignore the whole rule or route? Is it sufficient to just drop that specific match and add a condition to status? In any case, we'll need to work on adding conditions to status that can be used to represent unknown values for any enum field. I don't think removing enum validation itself really solves the issue for us here, the core issue seems to be that we need implementations to be able to handle unknown/unrecognized future values. The API conventions around enums do seem rather inconsistent/confusing. I know enum type validation is widespread in k/k APIs, and I don't think there are any great alternatives available. To contrast with some of the suggestions not to use enums, this is also part of API conventions:
|
If want to make controllers handle this properly, we need to put a test case with "UnknownEnumValue" into the conformance tests for each of the potential places where enums are going to be used. |
Thanks everyone for the great discussion. I kind of pushed a little hard here because I wanted to make sure we do something to clear this up. It sounds to me like the steps we need to take here are instead:
I've updated the title of the issue accordingly. |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale /assign I made this mess, I better clean it up. 😉 |
The Kubernetes API conventions strongly recommend against using OpenAPI Enum validation, because there is a strong implication that the set of enumerated values is immutable; implementations can reasonably expect that the entire set of an Enum is known. Because of this, for the core APIs, adding a value to or removing a value from an Enum is a breaking API change and requires an API version bump.
Before we go to beta, I'd like us to discuss our use of kubebuilder Enum tags, and whether it will make version management easier for these types to:
I can see an argument that because we have the experimental channel, the rules apply less, but I'm pretty reluctant to disregard lessons learned in the core APIs without a very good reason.
/kind design
I think?
The text was updated successfully, but these errors were encountered: