-
Notifications
You must be signed in to change notification settings - Fork 39.3k
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 kubebuilder tags to Condition type #92660
Conversation
/hold |
@@ -1367,28 +1368,39 @@ type Condition struct { | |||
// Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be | |||
// useful (see .node.status.conditions), the ability to deconflict is important. | |||
// +required | |||
// +kubebuilder:validation:Required | |||
// +kubebuilder:validation:Enum=Available;Progressing;Degraded |
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.
this is a regex in the validation code.
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.
Yeah, I based this on the comment above the type. The validation code looks like it uses different regexes conditionally which I think is more complex than the regex marker can do alone
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.
using an enum here is not correct... far more types than Available, Progressing, Degraded are supported
The regex validation seems to be conditional based on whether the type is qualified or not. I think that can be expressed like this:
(DNS1123_PATTERN/)?(QUALIFIED_NAME_PATTERN)
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.
@liggitt Ah, I'm not great with complex regexes so I wasn't aware if it could handle conditionals
Since dns1123 pattern is dns1123LabelFmt + "(\\." + dns1123LabelFmt + ")*"
and qualified name fmt is "(" + qnameCharFmt + qnameExtCharFmt + "*)?" + qnameCharFmt
, I tried substituting these into (DNS1123_PATTERN/)?(QUALIFIED_NAME_PATTERN)
(evaluated out). This ended up being pretty complex from what I can see, not sure if there's a good way to simplify it
/assign @liggitt @DirectXMan12 |
Type string `json:"type" protobuf:"bytes,1,opt,name=type"` | ||
// status of the condition, one of True, False, Unknown. | ||
// +required | ||
// +kubebuilder:validation:Required | ||
Status ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status"` |
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.
this is an appropriate place for an enum (True, False, Unknown)
ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,3,opt,name=observedGeneration"` | ||
// lastTransitionTime is the last time the condition transitioned from one status to another. | ||
// This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable. | ||
// +required | ||
// +kubebuilder:validation:Required |
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.
is there a time format or RFC3339 regex we can use here?
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.
it looks like we can use type: string and format: date-time
// The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt) | ||
// +required | ||
// +kubebuilder:validation:Required | ||
// +kubebuilder:validation:Pattern=^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]) |
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.
this matches asdfasfas.sadf.asdfas/bla$'_%
.
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.
This is what I got manually expanding the regexes currently used by the validation function (#92660 (comment)) Did I miss something or write that out wrong?
// +kubebuilder:validation:Required | ||
// +kubebuilder:validation:MaxLength=1024 | ||
// +kubebuilder:validation:MinLength=1 | ||
// +kubebuilder:validation:Pattern=`^[A-Za-z_][A-Za-z0-9_]*$` |
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.
this got expanded [A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?
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.
Updated
@deads2k @sttts think I addressed the comments here. There was some offline talk about trying to come up with a regex to match specifically non-zero rfc3339, is that still something we need or is a date-time format validation sufficient? (#92660 (comment)) |
95570fa
to
5588684
Compare
/retest |
Can you rebase this on master please? You've got an old version of the validation PR |
5588684
to
c70d777
Compare
Ah I did rebase it on master, I needed to rebase it on your branch from the validation PR. Updated and squashed |
also |
c70d777
to
9a32a70
Compare
@deads2k updated my commit and rebased on yours again |
Reason string `json:"reason" protobuf:"bytes,5,opt,name=reason"` | ||
// message is a human readable message indicating details about the transition. | ||
// This may be an empty string. | ||
// +required | ||
// +kubebuilder:validation:Required |
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.
we allow the message to be empty. See two lines up. The required bit is about serialization back to clients.
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.
This looks correct to me. The value can be an empty string, but the field must be specified or openapi validation will complain ("message":""
)
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.
This looks correct to me. The value can be an empty string, but the field must be specified or openapi validation will complain (
"message":""
)
Found it in my live test. The CR validation doesn't give slice numbers, so I was looking at the wrong item.
/lgtm |
/retest |
// +kubebuilder:validation:Required | ||
// +kubebuilder:validation:MaxLength=1024 | ||
// +kubebuilder:validation:MinLength=1 | ||
// +kubebuilder:validation:Pattern=`^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$` |
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.
Allowing commas. Not a fan....
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.
Same for colon. Hrm... gonna have to think about this.
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.
Allowing commas. Not a fan....
Matches the reality of the world I'm afraid. We have people interested in adopting now that have union reasons with delimiters
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.
I guess since we said "machine readable" this is the world we live in.
@damemi: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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/test-infra repository. I understand the commands that are listed here. |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: damemi, smarterclayton 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 |
/retest |
validation is finalized, removing hold. |
This PR may require API review. If so, when the changes are ready, complete the pre-review checklist and request an API review. Status of requested reviews is tracked in the API Review project. |
/label api-review |
What type of PR is this?
/kind api-change
What this PR does / why we need it:
This picks the changes from #92519 and adds kubebuilder validation tags for CRD generation
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
related to kubernetes/enhancements#1623