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

docs: Avoid omitempty with kubebuilder:validation:Required #1695

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

ebblake
Copy link
Contributor

@ebblake ebblake commented Oct 7, 2024

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.

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]>
@openshift-ci openshift-ci bot requested review from coreydaley and stleerh October 7, 2024 21:27
Copy link
Contributor

openshift-ci bot commented Oct 7, 2024

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@openshift-ci openshift-ci bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Oct 7, 2024
@ebblake
Copy link
Contributor Author

ebblake commented Oct 22, 2024

Ping @coreydaley @stleerh is this worth testing?

@JoelSpeed
Copy link
Contributor

/ok-to-test

/lgtm

@openshift-ci openshift-ci bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 23, 2024
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Oct 23, 2024
Copy link
Contributor

openshift-ci bot commented Oct 23, 2024

@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.

@JoelSpeed
Copy link
Contributor

/approve

Copy link
Contributor

openshift-ci bot commented Oct 23, 2024

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 23, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 8f2a2e1 into openshift:master Oct 23, 2024
2 checks passed
albertofaria pushed a commit to kubesan/kubesan that referenced this pull request Dec 4, 2024
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants