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

👻 Enhance regex patterns #1745

Merged
merged 1 commit into from
Oct 29, 2020
Merged

Conversation

Adirio
Copy link
Contributor

@Adirio Adirio commented Oct 27, 2020

Descrition

  • Used non-capturing groups when the info is not relevant
  • Simplified some expressions

Motivation

While non-capturing groups should be a bit more performant that capturing groups, the improvement will be negligible. The motivations is mainly improving the clarity and readability of the regex expressions by simplifying some patters and not having unused capture groups.

/kind cleanup

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 27, 2020
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 27, 2020
@Adirio
Copy link
Contributor Author

Adirio commented Oct 27, 2020

I used 👻 as this is a minor change that I don't think is worth to include in changelogs, but the verifier is not understanding it despite being mentioned in CONTRIBUTING.md. Guess I could change it to ✨ if needed.

dns1123SubdomainFmt string = dns1123LabelFmt + "(\\." + dns1123LabelFmt + ")*"
dns1035LabelFmt string = "[a-z]([-a-z0-9]*[a-z0-9])?"
dns1035LabelFmt string = "[a-z](?:[-a-z0-9]*[a-z0-9])?"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Adirio,

For we not add ore one dependency to the project we decided to copy and paste the implementation to validate.
We should not change this file unless it was changed in the k8s.io/apimachinery

See:

// This file's code was modified from "k8s.io/apimachinery/pkg/util/validation"
// to avoid package dependencies. In case of additional functionality from
// "k8s.io/apimachinery" is needed, re-consider whether to add the dependency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please revert the changes here?

Copy link
Contributor Author

@Adirio Adirio Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree with you if the code was copy-pasted, but it has been already modified. You can check it. So Convering that capture group into a non-capture group tells the future us reading the code that we are not using that capture group to take a substring out of the regex. It also avoid having to allocate some variables but the performance increase will be very small.

Copy link
Member

@camilamacedo86 camilamacedo86 Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catcher. I would prefer if possible we keep a copy and paste of https://github.com/kubernetes/apimachinery/blob/v0.18.6/pkg/util/validation/validation.go whcih would allow us to move to use the dependency if we wish without breaking changes. However, I will let it up to you and @estroz.

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why the changes made make the code more understandable or not. I think it also needs to be checked by @estroz.

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI @Adirio,

I am ok with the changes, however, I think it needs the @estroz ok as well if possible.
My concern would only : #1745 (comment)

Also, note that it is no passing in the CI. could you please fix that?

camilamacedo86
camilamacedo86 previously approved these changes Oct 27, 2020
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 27, 2020
@camilamacedo86 camilamacedo86 dismissed their stale review October 27, 2020 13:48

I think it also needs to be checked by @estroz.

@camilamacedo86 camilamacedo86 removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 27, 2020
@kubernetes-sigs kubernetes-sigs deleted a comment from k8s-ci-robot Oct 27, 2020
- Used non-capturing groups when the info is not relevant
- Simplified some expressions

Signed-off-by: Adrian Orive <adrian.orive.oneca@gmail.com>
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 27, 2020
@@ -47,27 +47,27 @@ var _ = Describe("Resource Options", func() {
options := &Options{Group: "crew", Version: "1", Kind: "FirstMate"}
Expect(options.Validate()).NotTo(Succeed())
Expect(options.Validate().Error()).To(ContainSubstring(
`version must match ^v\d+(alpha\d+|beta\d+)?$ (was 1)`))
`version must match ^v\d+(?:alpha\d+|beta\d+)?$ (was 1)`))
Copy link
Member

@camilamacedo86 camilamacedo86 Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not use fmt.String and have the regex as a const arg of it?

Copy link
Contributor Author

@Adirio Adirio Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also thought of that to prevent having it hardcoded a dozen times the thing is that the string is not exported from its package. I think the better approach would be to create an expecific error instead a generic one and test if this yields this kind of error. But I just wanted to do the less changes to get it to pass Travis for now.

Copy link
Contributor

@estroz estroz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 29, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Adirio, estroz

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 Oct 29, 2020
@prafull01
Copy link
Contributor

/test pull-kubebuilder-e2e-k8s-1-16-2

@k8s-ci-robot k8s-ci-robot merged commit 6a639d5 into kubernetes-sigs:master Oct 29, 2020
@Adirio Adirio deleted the regex branch October 29, 2020 18:22
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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants