-
Notifications
You must be signed in to change notification settings - Fork 211
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
Implement support for Enum values #218
Comments
I've started toying with adding a new tag which I'm currently calling "enum": // A string with a list of accepted values Here is the branch I am currently working on: https://github.com/kubernetes/kube-openapi/compare/master...yannh:enum-support?expand=1 I would love early feedback on this. Currently this only works for "simple" properties. |
Are these enums "closed" in the sense that they will never be extended in the future? In general, I am not against extending the schema. Please compare with the recent defaulting KEP by @apelisse. It is the same direction. It has some thoughts about syntax. Also keep in mind that new tags must work with kubebuilder cc @DirectXMan12 |
Thanks Stefan, I completely agree with the sentiment. An alternative syntax (I don't know if it's better), since "enums" always have to be lists, could be to repeat the tag:
That definitely uses more space. Also, something else that is important to note. We already have mechanisms for "enums" by defining a string type, and then giving this type values. We could possibly use that mechanism somehow to specify the values of an enum. Other related problem, we don't have a good mechanism to document the possible values of an enum, i.e. "TCP means Transmission Control Protocol, bla bla bla" (today, the comments we define on the constants are silently dropped, there is an issue somewhere about this, @thockin) |
I'd prefer if folks synced with roughly what we use in kubebuilder -- see https://book.kubebuilder.io/reference/markers/crd-validation.html for the marker itself, and https://book.kubebuilder.io/reference/markers.html#marker-syntax for the syntax. |
Hi @DirectXMan12 ! That would mean, support for both "Surrounding them with curly braces and separating with commas" and "Separated by semicolons" - for a single field called "+Enum"? I'm fine with that - I would probably re-use your parsing code, if that's ok. @apelisse : do we need to specify the type of an enum, or should it be inferred from the parameter type? |
That seems very different from what we do for built-in types? I'd rather avoid having to do: // Protocol defines network protocols supported for things like container ports.
type Protocol string
const (
// ProtocolTCP is the TCP protocol.
ProtocolTCP Protocol = "TCP"
// ProtocolUDP is the UDP protocol.
ProtocolUDP Protocol = "UDP"
// ProtocolSCTP is the SCTP protocol.
ProtocolSCTP Protocol = "SCTP"
)
type ContainerPort struct {
// ... omitted fields ...
// Required: Supports "TCP", "UDP" and "SCTP"
// +optional
// +enum=["TCP", "UDP", "SCTP"]
Protocol Protocol
} |
Agree. I should be able to say something like:
and get docs that say:
That's a trivial case. What about a case where the enum values actually need their own comments?
with the resulting docs:
Now, I have intentionally violated godoc here (another reason for an IDL), but we could try to follow it better with some conventions. This is still kind of a trivial example. If the per-value comments were longer or multi-sentence, this would be a poor fit.
producing something like
or even:
The TL;DR of what I am blathering on about is that we should think about how people consume the results and define our conventions and processing steps to optimize for that. I don't think users want to see "this field is a ProcMountType" and then have to click-thru to the definition of that type to see the valid values. I think they want to see the valid values right alongside the field. I could be convinced that click-thru to get the MEANINGS of the fields is acceptable, if openAPI can support that. E.g.
|
Thanks for the comments! From my point of view - I am only interested in automated schema validation - any solution presented here would work for me. It however seems to go a bit beyond my understanding of this codebase - I'm not sure I would be able to implement these suggestions. |
@yannh, Thanks for your help! We have to think of this problem holistically, I'd love to help you if you want to give it a try :-) |
Is there a reason not to generate definitions for each enum type and use them in various places (other definitions, parameters, etc.) ? In the current situation, it is impossible to generate validating code, and it forces developers to hardcode enumeration values everywhere. |
For posterity-- I had attempted to solve this problem in late 2019: #176. I decided to wait until a openapi v3 because it would be a breaking change to v2, and it looks like the bots closed the PR for me after I ignored it for too long. |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
/remove-lifecycle stale |
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 |
The Kubernetes project currently lacks enough active 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 rotten |
Not sure if we need to close this, the feature is only alpha at the moment. Let's probably keep it open until beta at least. |
For reference, this is the KEP and this is the enhancement. |
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 |
The Kubernetes project currently lacks enough active 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 rotten |
This is beta now, maybe we can close it? |
Yes! We can consider this implemented. |
@jiahuif: Closing this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Initially opened here kubernetes/kubernetes#97503 but I believe this improvement suggestion might be better here? This is about supporting parameters that support a list of values:
The "Protocol" parameter of a ContainerPort needs to be one of 'TCP', 'UDP', or 'SCTP' - as documented here
kubernetes/staging/src/k8s.io/api/core/v1/types.go
Line 1837 in ddf3eb5
// Protocol for port. Must be UDP, TCP, or SCTP.
However this restriction is not explicit in the generated OpenAPI file: https://raw.githubusercontent.com/kubernetes/kubernetes/ddf3eb5a1877338da806c2be15b53f456b6342c9/api/openapi-spec/swagger.json
There are a number of similar parameters which only accept a list of values - that restriction not being part of the generated OpenAPI file - "RestartPolicy" being another one.
This restricts the amount of validation that schema validators (such as Kubeval/Kubeconform) can do - and confuses users who would expect the tool to catch this kind of error.
OpenAPI does support enums though - is this a restriction of the tooling? It would be great to have these as part of the OpenAPI schema! pray
The text was updated successfully, but these errors were encountered: