-
Notifications
You must be signed in to change notification settings - Fork 428
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 more complex validations (oneOf/anyOf/allOf/etc) #461
Comments
There is obviously a good amount of complexity in even supporting this scenario, as in order to generate a CRD with the above shape, there needs to be some way to create various validation "groups" and join them with an operator... maybe something like this...?
I'm wondering if there's thought/energy in this space - I looked around and didn't really see many issues related to this topic (although there was #298 which is somewhat related). |
I think #298 is the bulk of the existing discussion. Largely, the background here is that we wanted to make it really hard/impossible to produce non-structural schemas (considering they're "invalid" in the soft sense -- you can't use new features with non-structural schemas). I think, at the very least, we can extend/augment the union markers to generate validation, so that the patterns captured by To clarify from your usecase a bit further, what's the desired intent of the validation? Specifically, are you saying that:
|
The above was just an example honestly, speaking about a general problem which I think will solve my specific problem. It's possible I generalized a bit too soon though as you're right the case above is really a union case (and there are specific recommendations from Kubernetes on how to deal with those based on this enhancement proposal for unions) My actual specific use case is: I want to create a CRD where there are two distinct sets of required parameters. For example something like this dummy CRD for a SQL database in a cloud:
I'm trying to convey that there are 2 (or 3 or whatever) minimum property sets for this resource. Structurally the object is the same regardless though (so it adheres to the structural schema requirements). Ideally I could encode these requirements into the CRD itself, so that users land into one of the two supported "flavors". Drawing parallels to code I want two different constructors/factory methods for this CRD type. I know there are probably other solutions to accomplishing this goal (like putting the delta between each set of required properties into their own struct and marking them all required but the top level struct optional on the spec), but that forces me to increase the complexity of the resource by adding nesting, and especially for the common case I'm thinking of (one set is always just cloudName, the other set is cloudName + a bunch of properties) it would force most of the properties down a level since the delta between each set of required properties is large. Alternatively I could go full union-style and actually make two shapes but again that ends up complicating the structure in a way that isn't technically required by the YAML. |
This would also be helpful over at the Cilium project as well. Our use-case is even simpler:
Essentially, we'd like to say that only one of endpoint selector or node selector must be provided, but not both. |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/remove-lifecycle stale |
Any news about this? |
I'd say the
Would be great to get controller-gen support for this! |
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 |
This is also something that would be useful in the Rook (github.com/rook/rook) project. |
I can't find any good documentation for |
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. |
I need to define the a
I suppose the only way to specify this is with the help of |
/remove-lifecycle stale |
Updated link to relevant KEP: https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/1027-api-unions/README.md. Links to it are broken in older comments, and also in #298. |
#298 has been closed as it was a stale/rotten PR. Do we have any idea how someone could implement |
@adambkaplan IMO this should be implemented on the basis of the the union KEP. I had a chat with @apelisse on Slack regarding this, and the advice was to wait till the KEP was implemented for native/in-tree types. But I would be happy to take a look at implementing this here, but my bandwidth is limited, as I guess it is for everyone. 😄 A couple of blocking technical PRs (testdata regeneration) got merged yesterday.... |
I wouldn't hold my breath. The feature is not in 1.27, nor is it really planned for a future release. I'm not sure when we'll find the time to work on it. |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale Still something we would like to see, but the upstream union design seem to be blocked. |
Gateway API appears to need support for this very simple use case:
xref: https://github.com/kubernetes-sigs/gateway-api/pull/2246/files#r1276849955 |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
This is still highly relevant. /remove-lifecycle stale |
The discussion around this seems too narrowly focused on unions. I read https://kubernetes.io/blog/2019/06/20/crd-structural-schema/ and its definition of "structural schema" seems like an overreaction to the stated problem, which is not declaring all the content. The opening comment in this issue has a good example. By conjoining "properties" with "oneOf", it declares all the content (the "properties" does that). Conjoining "properties" with "allOf" or "anyOf" would also do that --- without looking like a union. |
@MikeSpreitzer not exactly sure I understand your comment right. This issue here is purely about controller-tools not being able to express everything that is valid in structural schemas. The Side-note: probably, with CEL it is already possible to express a union through controller-tools markers. So this issue here is not a blocker for unions anymore. |
We have used CEL to validate unions for both optional and required union members. In the example below we have a field
|
Probably obvious, but I think this part of the problem could be covered by running the resulting CRD through structural schema validation. |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
Generally makes sense /lifecycle frozen |
@sbueringer: GuidelinesPlease ensure that the issue body includes answers to the following questions:
For more details on the requirements of such an issue, please see here and ensure that they are met. If this request no longer meets these requirements, the label can be removed 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-sigs/prow repository. |
According to the structural schema, CRD schemas such as the one below (from the linked article) are allowed:
As far as I can tell, it is not possible to generate a schema of this shape using controller-gen today. Specifically, the
oneOf
validation at the bottom cannot be represented using Kubebuilders validation annotations, as there is no way to specifyoneOf
(oranyOf
/allOf
/etc) via annotations that I can tell.Is there a plan or vision for having controller-gen support more complex validation scenarios (or does it already and I've just missed how?)
The text was updated successfully, but these errors were encountered: