Skip to content

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

Merged
k8s-ci-robot merged 3 commits into
kubernetes-sigs:mainfrom
gyohuangxin:HTTPQueryParamMatch_validation
Mar 23, 2023
Merged

k8s-ci-robot merged 3 commits into
kubernetes-sigs:mainfrom
gyohuangxin:HTTPQueryParamMatch_validation

Conversation

@gyohuangxin

@gyohuangxin gyohuangxin commented Mar 9, 2023 •

Copy link
Copy Markdown

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 requested review from bowei and robscott March 9, 2023 01:55
@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
Copy Markdown
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
Comment thread apis/v1beta1/httproute_types.go Outdated
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=256
// +kubebuilder:validation:Pattern=`^[A-Za-z0-9!#$%&'*+\-.^_\x60|~]+$`

Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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

@robscott robscott left a comment

Copy link
Copy Markdown
Member

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.

Comment thread apis/v1beta1/httproute_types.go Outdated
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=256
// +kubebuilder:validation:Pattern=`^[A-Za-z0-9!#$%&'*+\-.^_\x60|~]+$`

Copy link
Copy Markdown
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.

@sunjayBhatia sunjayBhatia left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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

shaneutt commented Mar 16, 2023 •

Copy link
Copy Markdown
Member

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
Huang Xin added 2 commits March 18, 2023 20:38
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
@k8s-ci-robot
k8s-ci-robot requested a review from shaneutt March 20, 2023 06:31
Comment thread apis/v1beta1/shared_types.go 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
Copy Markdown
Author

@robscott Could you review this? Thanks

@shaneutt shaneutt left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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

Details 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

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