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

Add shared type HeaderName and use it for GRPCHeaderName, HTTPHeaderName and QueryParamMatchName #1796

Merged

Conversation

gyohuangxin
Copy link
Member

@gyohuangxin gyohuangxin commented Mar 9, 2023

What type of PR is this?

/kind bug

What this PR does / why we need it:

Add pattern for query param name in HTTPQueryParamMatch like other items' names to avoid illegal names.

Which issue(s) this PR fixes:

Fixes #1729

Does this PR introduce a user-facing change?:

Yes, illegal names like " " will be not allowed for query param name in HTTPQueryParamMatch.

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 9, 2023
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Mar 9, 2023
@gyohuangxin
Copy link
Member Author

@shaneutt Can you review it? Thanks.

@shaneutt shaneutt self-requested a review March 9, 2023 02:16
@shaneutt shaneutt self-assigned this Mar 9, 2023
@shaneutt shaneutt added this to the v0.7.0 milestone Mar 9, 2023
@@ -452,6 +452,7 @@ type HTTPQueryParamMatch struct {
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=256
// +kubebuilder:validation:Pattern=`^[A-Za-z0-9!#$%&'*+\-.^_\x60|~]+$`
Copy link
Member

Choose a reason for hiding this comment

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

Was this pattern specifically pulled from a reference somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Can we use HTTPHeaderName as the type here instead of copying the regex? Would make this easier to maintain going forward.

@shaneutt shaneutt requested a review from youngnick March 13, 2023 14:35
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 13, 2023
Copy link
Member

@robscott robscott left a comment

Choose a reason for hiding this comment

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

Thanks @gyohuangxin! One tiny nit but otherwise LGTM.

@@ -452,6 +452,7 @@ type HTTPQueryParamMatch struct {
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=256
// +kubebuilder:validation:Pattern=`^[A-Za-z0-9!#$%&'*+\-.^_\x60|~]+$`
Copy link
Member

Choose a reason for hiding this comment

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

Can we use HTTPHeaderName as the type here instead of copying the regex? Would make this easier to maintain going forward.

Copy link
Member

@sunjayBhatia sunjayBhatia left a comment

Choose a reason for hiding this comment

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

generally seems right, but agree with @robscott's idea to not have to repeat the same regex pattern many places, i don't know if adding another layer of type aliasing would be what we want to do/even work as we intend but that might be an idea to explore (e.g GRPCHeaderName, HTTPHeaderName and query param match name all use the same underlying more neutrally-named type)

@gyohuangxin
Copy link
Member Author

Thanks for your comments. Agreed with @sunjayBhatia , the better solution is to introduce a shared type like HeaderName in apis/v1beta1/shared_types.go then any name properties (e.g GRPCHeaderName, HTTPHeaderName and QueryParamMatchName) can use them, so that we can reduce regular expression maintenance.
@robscott @shaneutt What do you think?

@shaneutt
Copy link
Member

shaneutt commented Mar 16, 2023

Thanks for your comments. Agreed with @sunjayBhatia , the better solution is to introduce a shared type like HeaderName in apis/v1beta1/shared_types.go then any name properties (e.g GRPCHeaderName, HTTPHeaderName and QueryParamMatchName) can use them, so that we can reduce regular expression maintenance. @robscott @shaneutt What do you think?

Yep sgtm, setting to draft to sort that out so this doesn't accidentally get merged 👍

@shaneutt shaneutt marked this pull request as draft March 16, 2023 13:07
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 16, 2023
Signed-off-by: Huang Xin <xin1.huang@intel.com>
…ame and QueryParamMatchName

Signed-off-by: Xin Huang <xin1.huang@intel.com>
@gyohuangxin gyohuangxin force-pushed the HTTPQueryParamMatch_validation branch from abafab3 to d1202af Compare March 18, 2023 14:00
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 18, 2023
@gyohuangxin gyohuangxin changed the title Add pattern for query param name in HTTPQueryParamMatch Add shared type HeaderName and use it for GRPCHeaderName, HTTPHeaderName and QueryParamMatchName Mar 20, 2023
@gyohuangxin gyohuangxin marked this pull request as ready for review March 20, 2023 06:31
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 20, 2023
apis/v1beta1/shared_types.go Outdated Show resolved Hide resolved
@shaneutt shaneutt requested a review from robscott March 20, 2023 12:37
@k8s-ci-robot k8s-ci-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 20, 2023
Signed-off-by: Huang Xin <xin1.huang@intel.com>
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 20, 2023
@gyohuangxin
Copy link
Member Author

@robscott Could you review this? Thanks

Copy link
Member

@shaneutt shaneutt left a comment

Choose a reason for hiding this comment

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

Rob approved previously just with the caveat of the common type, we're all set thank you @gyohuangxin!!! 🥳

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gyohuangxin, shaneutt, sunjayBhatia

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 merged commit 54a7bc4 into kubernetes-sigs:main Mar 23, 2023
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/bug Categorizes issue or PR as related to a bug. 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.

Validation for query param name in HTTPQueryParamMatch allows whitespace characters
5 participants