-
Notifications
You must be signed in to change notification settings - Fork 426
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
Add ability to set default field requirement status #211
Conversation
/hold might change this to cover both cases and let people set their default or keep the current default |
I've updated this with the ability to set a package-level |
Why another tag? Aren‘t +required/optional enough? |
@sttts you mean just re-use required/optional at the package level? Yeah, I guess we could do it that way too. However |
more markers is fine (in implementation). But for the users, it looks like one, right? just different levels. |
2eab8e7
to
449036f
Compare
@sttts Updated this to have a |
/hold cancel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comments inline, otherwise lgtm
@DirectXMan12 updated with your feedback, can you please tag? |
af492d2
to
d86df0b
Compare
force-pushed an update to register the Will merge once tests pass. |
Using +kubebuilder:validation:Optional/Required at the package level sets the default value for fields in that package to that value, while using the opposite marker on fields in that package sets them as an exception. The `+optional` marker is an alias for `+kubebuilder:validation:Optional`, for interoperability with main Kubernetes.
Removed the TODO for |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: damemi, DirectXMan12 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 |
Currently the `+optional` and `+nullable` markers don't work. I've fixed `optional` by making sure the `FieldOnlyMarkers` slice that was added in kubernetes-sigs#211 actually gets added to `AllDefinitions`. In the current code, `+nullable` would actually only be recognized as `+kubebuilder:validation:Nullable=true`, so I'm updating this to be more consistent with what's expected for that marker.
This introduces a
// +kubebuilder:validation:[Required/Optional]
marker which can be applied to both packages and fields. Placing it at the package level determines the default requirement for fields in that package (ie, a package marked with// +kubebuilder:validation:Optional
will assume no fields are required unless specifically marked with// +kubebuilder:validation:Required
).If no package-level tag is set, this defaults to the current behavior of assuming all fields not tagged with
omitempty
,inline
, or (now)// +kubebuilder:validation:Optional
are required, so this change doesn't break current use cases.