-
Notifications
You must be signed in to change notification settings - Fork 418
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
🐛 Fix int or string pattern application #611
🐛 Fix int or string pattern application #611
Conversation
@JoelSpeed can we properly test this by extending pkg/crd/testdata/cronjob_types.go with a field of type IntOrString and a pattern? |
Yes of course! I did have a quick scan for something testing the CRD generation but didn't find this, will take a look at adding a test today |
to a perecentage or integer. The XIntOrString marker is a requirement | ||
for having a pattern on this type. | ||
pattern: ^((100|[0-9]{1,2})%|[0-9]+)$ | ||
x-kubernetes-int-or-string: true |
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.
Did you btw if the apiserver correctly deals with this (i.E. applies the pattern when you submit a string but not when you submit an int)?
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 tested this manually in kind. I could apply any number I wanted but was restricted if I added a percent sign
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.
/label tide/merge-method-squash
/lgtm
/assign @vincepri
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, JoelSpeed, vincepri 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 |
This allows users to set the schema.XIntOrString property during the marker validation phase. Which in turn allows other markers to rely on the fact that the type is an IntOrString. Eg. This allows you to set a pattern on an IntOrStr type
1dc1a21
to
f1dc0d0
Compare
Had to fix a typo in the comment on the new marker, no other changes |
/lgtm |
This is a follow up to fix #608 which I hadn't appropriately tested before proposing it 😞
I tried this out this morning and worked out that it wasn't working, there are two reasons for this.
The condition check was wrong, we meant to check for the schema not being an IntOrString.
The second issue is that the additional information for the type that the generator applies (eg setting XIntOrString=true) is not done until way later in the generation than the markers being applied. Looking at the existing code, the "fix" for this seems to be that you have to apply an additional marker, eg the Type marker, that sets the required fields early.
So this introduces a new marker
// +kubebuilder:validation:XIntOrString
which marks the type as an IntOrString early to allow the pattern marker to pick this up. Not sure if this is the best approach given Solly's old notes, but it seems to be in-keeping with the rest of the markers/CC @alvaroaleman @vincepri