Skip to content

🐛 inject min boundaries for +k8s:required on strings, maps, and slices - #1458

Open
lalitc375 wants to merge 2 commits into
kubernetes-sigs:mainfrom
lalitc375:required-parity
Open

🐛 inject min boundaries for +k8s:required on strings, maps, and slices#1458
lalitc375 wants to merge 2 commits into
kubernetes-sigs:mainfrom
lalitc375:required-parity

Conversation

@lalitc375

@lalitc375 lalitc375 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

What does this do, and why do we need it?

This PR updates the CRD generation logic for the +k8s:required marker to automatically apply minimum boundaries to strings, arrays, and objects.

Specifically, when a field is marked as required, this change will now automatically inject:

  • minLength=1 for string types.
  • minItems=1 for array (slice) types.
  • minProperties=1 for object (map) types.

This aligns with the implementation of +k8s:required of validation-gen of kubernetes. https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/validate/required.go

There is no clean way to model required int in CRD as of now. We will handle it separately.

There are no prod usage outside of k/k for +k8s:required. It is fine to change now then later. CRs are ratcheted, It is safe to change it. https://grep.app/search?q=%2Bk8s%3Arequired+

@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 29, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @lalitc375. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

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.

Details

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.

@kubernetes-prow kubernetes-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 29, 2026
@lalitc375 lalitc375 changed the title bug fix: inject min boundaries for +k8s:required on strings, maps, and slices 🐛 inject min boundaries for +k8s:required on strings, maps, and slices Jul 29, 2026
@lalitc375

Copy link
Copy Markdown
Contributor Author

/assign @JoelSpeed

Comment thread pkg/crd/markers/validation.go
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lalitc375
Once this PR has been reviewed and has the lgtm label, please ask for approval from joelspeed. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details 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

@JoelSpeed

Copy link
Copy Markdown
Contributor

/ok-to-test

CC @sbueringer @alvaroaleman

This aligns the markers to their upstream behaviour, but is technically a breaking change for our users who might have adopted these already (though they are pretty new). I'm in favour of merging this, so please LMK if you have concerns

@kubernetes-prow kubernetes-prow 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 Sep 4, 2026
…and slices

This updates the '+k8s:required' marker logic to automatically apply minLength=1 for strings, minProperties=1 for maps, and minItems=1 for slices if they are not already explicitly set. It also adds robust golden file test cases to ensure these constraints are propagated appropriately, including testing against pointer fields.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants