🐛 inject min boundaries for +k8s:required on strings, maps, and slices - #1458
🐛 inject min boundaries for +k8s:required on strings, maps, and slices#1458lalitc375 wants to merge 2 commits into
Conversation
|
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 Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
|
/assign @JoelSpeed |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lalitc375 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/ok-to-test 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 |
…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.
c4c4c57 to
2bc8920
Compare
What does this do, and why do we need it?
This PR updates the CRD generation logic for the
+k8s:requiredmarker 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=1forstringtypes.minItems=1forarray(slice) types.minProperties=1forobject(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+