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

feat(HTTPRouteMatcher): implement http method filter #733

Merged

Conversation

secustor
Copy link
Contributor

@secustor secustor commented Jul 23, 2021

What type of PR is this?
/kind feature
/kind api-change

What this PR does / why we need it:
This PR adds a HTTPMatcher to allow match one or more specific HTTP methods.
If multiple are defined it is defined as logical OR.

Which issue(s) this PR fixes:

Fixes #624

Does this PR introduce a user-facing change?:

HTTPRoute now supports matching based on HTTP methods.

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API labels Jul 23, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @secustor!

It looks like this is your first PR to kubernetes-sigs/gateway-api 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/gateway-api has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 23, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @secustor. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 23, 2021
@@ -408,6 +408,10 @@ type HTTPQueryParamMatch struct {
Value string `json:"value"`
}

// HTTPMethod describes how to select a HTTP route by matching the HTTP
// method.
type HTTPMethod string

Choose a reason for hiding this comment

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

Is it an appropriate layer to add some kind of enum to allow specific values? E.g. the http methods defined by the HTTP spec.

See https://datatracker.ietf.org/doc/html/rfc7231#section-4 and here https://datatracker.ietf.org/doc/html/rfc5789#section-2

I thinking more about a way to avoid mistakes when defining the paths and only when the config is applied to not route through to the correct service

Copy link
Contributor Author

@secustor secustor Jul 23, 2021

Choose a reason for hiding this comment

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

Alternatively we could reuse the HttpMethod from the genproto package which is already a dependency. https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/scheduler/v1#HttpMethod

Copy link
Member

Choose a reason for hiding this comment

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

I like the idea of an enum here. I'd also recommend adding enum validation to the field as shown here: https://github.com/kubernetes-sigs/gateway-api/blob/master/apis/v1alpha2/httproute_types.go#L271.

I think I'd prefer defining our own custom types instead of reusing the ones defined in genproto. That will allow us more flexibility in terms of documentation and support levels.

Also appreciate the RFC references by @brunoarueira. Where possible, we like to reference specific RFCs when documenting a feature/field in the comments (example: https://github.com/kubernetes-sigs/gateway-api/blob/master/apis/v1alpha2/httproute_types.go#L342).

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW there is an IANA registry for HTTP methods

https://www.iana.org/assignments/http-methods/http-methods.xhtml

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 for the work on this!

/ok-to-test

apis/v1alpha2/httproute_types.go Outdated Show resolved Hide resolved
@@ -408,6 +408,10 @@ type HTTPQueryParamMatch struct {
Value string `json:"value"`
}

// HTTPMethod describes how to select a HTTP route by matching the HTTP
// method.
type HTTPMethod string
Copy link
Member

Choose a reason for hiding this comment

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

I like the idea of an enum here. I'd also recommend adding enum validation to the field as shown here: https://github.com/kubernetes-sigs/gateway-api/blob/master/apis/v1alpha2/httproute_types.go#L271.

I think I'd prefer defining our own custom types instead of reusing the ones defined in genproto. That will allow us more flexibility in terms of documentation and support levels.

Also appreciate the RFC references by @brunoarueira. Where possible, we like to reference specific RFCs when documenting a feature/field in the comments (example: https://github.com/kubernetes-sigs/gateway-api/blob/master/apis/v1alpha2/httproute_types.go#L342).

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 23, 2021
@secustor secustor requested a review from robscott July 24, 2021 20:29
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.

Mostly LGTM, just a few nits.

apis/v1alpha2/httproute_types.go Outdated Show resolved Hide resolved
apis/v1alpha2/httproute_types.go Outdated Show resolved Hide resolved
apis/v1alpha2/httproute_types.go Outdated Show resolved Hide resolved
@robscott
Copy link
Member

/cc @bowei @hbagdi @youngnick

@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 Jul 26, 2021
HTTPMethodConnect HTTPMethod = "CONNECT"
HTTPMethodOptions HTTPMethod = "OPTIONS"
HTTPMethodTrace HTTPMethod = "TRACE"
HTTPMethodPatch HTTPMethod = "PATCH"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this is a good idea or not.
Custom HTTP methods are a thing, although not common in practice.
For the 99% of the cases, these defined methods will suffice.
If there comes a time when we want to support custom HTTP methods, how can we do so without a breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I'm not mistaken it is already possible to match the HTTP method via header value match.
In this case we could reference the user to that method.

The alternatives are dropping enum and revert to string or a more complex structure instead of the simple key-value pair.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm not mistaken it is already possible to match the HTTP method via header value match.

How so?

cc @robscott @jpeach

Copy link
Contributor

Choose a reason for hiding this comment

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

With :method pseudo-header (https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.1)

If we go down this route we need to make it explicit in the spec that implementation must accept pseudo-headers though.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we go down this route we need to make it explicit in the spec that implementation must accept pseudo-headers though.

We should clarify this regardless. Else implementations will drift in this aspect.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, +1 on defining pseudo-header matching. Controllers can map the pseudo header name to the underlying proxy control.

Copy link
Contributor

Choose a reason for hiding this comment

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

I opened up #740 to track this conversation.

My only slight hesitation is that then there are two ways to do the same thing. In this case, that might be okay because custom HTTP methods are not common. Not really sure.

@robscott robscott added this to the v1alpha2 milestone Jul 28, 2021
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 29, 2021
@secustor secustor requested review from hbagdi and robscott July 29, 2021 17:55
apis/v1alpha2/httproute_types.go Outdated Show resolved Hide resolved
apis/v1alpha2/httproute_types.go Outdated Show resolved Hide resolved
@secustor secustor requested a review from hbagdi July 31, 2021 11:39
Copy link
Contributor

@hbagdi hbagdi left a comment

Choose a reason for hiding this comment

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

I was about to lgtm this but found a couple of small issues.

apis/v1alpha2/httproute_types.go Outdated Show resolved Hide resolved
apis/v1alpha2/httproute_types.go Outdated Show resolved Hide resolved
@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 Aug 2, 2021
@robscott
Copy link
Member

robscott commented Aug 2, 2021

Thanks! Will leave LGTM for someone else.

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: robscott, secustor

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 Aug 2, 2021
@robscott robscott added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Aug 2, 2021
@hbagdi
Copy link
Contributor

hbagdi commented Aug 2, 2021

@secustor Thank you for your contribution!
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 2, 2021
@k8s-ci-robot k8s-ci-robot merged commit c4a3a3e into kubernetes-sigs:master Aug 2, 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. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

Method based routing
7 participants