-
Notifications
You must be signed in to change notification settings - Fork 475
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
docs: Avoid omitempty with kubebuilder:validation:Required #1695
Conversation
When writing a unionDiscriminator, use of ",omitempty" in the JSON spec overrides any attempt to require the discriminator via the tag +kubebuilder:validation:Required. It is confusing to have the docs recommend two conflicting pieces of information for the same field, and it makes more sense for the discriminator to be mandatory (even though, as correctly pointed out below, all of the other fields of the union type must be optional). See also kubernetes-sigs/kubebuilder#3794, where a debate was held on whether kubebuilder should document the interplay, which in turn pointed back to controller-tools conventions. Signed-off-by: Eric Blake <[email protected]>
Hi @ebblake. Thanks for your PR. I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
Ping @coreydaley @stleerh is this worth testing? |
/ok-to-test /lgtm |
@ebblake: all tests passed! Full PR test history. Your PR dashboard. 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. I understand the commands that are listed here. |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JoelSpeed The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
If our CEL validation requires a string to be non-empty, but we also use ",omitempty" in the JSON description of that member, the latter takes over and the user can still omit the element. We introduced this pattern by copy-and-paste of OpenShift coding guidelines for discriminated unions, but that example has since been updated (openshift/enhancements#1695), so update our code to follow suit. Signed-off-by: Eric Blake <[email protected]>
When writing a unionDiscriminator, use of ",omitempty" in the JSON spec overrides any attempt to require the discriminator via the tag +kubebuilder:validation:Required. It is confusing to have the docs recommend two conflicting pieces of information for the same field, and it makes more sense for the discriminator to be mandatory (even though, as correctly pointed out below, all of the other fields of the union type must be optional).
See also kubernetes-sigs/kubebuilder#3794, where a debate was held on whether kubebuilder should document the interplay, which in turn pointed back to controller-tools conventions.