Skip to content
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

Merged

Conversation

JoelSpeed
Copy link
Contributor

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

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 7, 2021
@alvaroaleman
Copy link
Member

@JoelSpeed can we properly test this by extending pkg/crd/testdata/cronjob_types.go with a field of type IntOrString and a pattern?

@JoelSpeed
Copy link
Contributor Author

@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
Copy link
Member

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)?

Copy link
Contributor Author

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

Copy link
Member

@alvaroaleman alvaroaleman left a 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

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Sep 13, 2021
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 13, 2021
@vincepri
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 15, 2021
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
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 16, 2021
@JoelSpeed
Copy link
Contributor Author

Had to fix a typo in the comment on the new marker, no other changes

@alvaroaleman
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 16, 2021
@k8s-ci-robot k8s-ci-robot merged commit 9440165 into kubernetes-sigs:master Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants