-
Notifications
You must be signed in to change notification settings - Fork 213
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
feature: add explicit +required #448
Conversation
This stems from the required field not having the correct (non-pointer) type right? This tag's main use case would be for legacy |
I don't think in general we have guidance for API types that all required fields should be non-omitempty or non-pointer. A pointer historically has been the only way to check for if the field was supplied (so that the required error can be thrown in the first place) especially if I think API authors will set the type to whatever they'd like it to be, and should make able to make the schema reflect their desired validation logic without impacting the type system. I'm also not sure if we should even be looking at A newer more recent field affected by this problem is ValidatingAdmissionPolicy's |
This is true to an extent. However, the types do have an impact on what kind of validation would be available, especially around ptr vs struct fields. eg: nullable. I do see your point of checking for existence and throwing the error though. Adding a +required tag seems fine for fixing that restriction, although this feels more like a bandaid solution. |
Struct types which override
I had also considered |
Ah right 😆, yeah I agree it's hard to come up with a perfect solution without revamping a large part of the validation system. Overall +1 on this approach |
+1 to |
That makes sense, the tags should take precedent over go structs. Don't forget to update the k8s docs for usage and best practices. LGTM once TODO comment on L329 is removed. |
24efcdb
to
f0e1bdd
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alexzielenski, Jefftree 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 |
While annotating native type schemas using our marker comments, I am finding that there are a few native types that have
omitempty
but are treated asrequired
.One example is
VolumeNodeAffinity
which has a pointer fieldRequired
that is not included in the list of required fields due to itsomitempty
tag:https://github.com/kubernetes/kubernetes/blob/2ce04fc04bf2cbbbacf2f184fd9ebd4e99d65430/staging/src/k8s.io/api/core/v1/types.go#L383-L387
https://github.com/kubernetes/kubernetes/blob/7972f0309ce8bad3292f3291718361367b2e58fe/pkg/apis/core/validation/validation.go#L7308-L7312
/cc @Jefftree
wdyt. I also thought of
+optional=false
since that has benefit of not adding another tag to represent the same concept; but its kinda weird