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

Switching Header and Query Param matching to use lists #657

Merged

Conversation

robscott
Copy link
Member

@robscott robscott commented May 10, 2021

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

What this PR does / why we need it:
This matches the API conventions that prefer lists of named subobjects over maps.

Does this PR introduce a user-facing change?:

Header and Query Param matching are now represented with lists of named subobjects instead of maps.

@robscott robscott added this to the v1alpha2 milestone May 10, 2021
@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 10, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: robscott

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 requested review from bowei and danehans May 10, 2021 18:39
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 10, 2021
// If multiple entries specify equivalent header names, the first entry with
// an equivalent name MUST be given precedence. Due to the
// case-insensitivity of header names, "foo" and "Foo" are considered
// equivalent.
Copy link
Contributor

Choose a reason for hiding this comment

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

Question for clarification:

headers:
- name: foo
  value: bar
- name: Foo
   value: bar1

What happens if a request with header foo: bar1 comes in? Is it matched or not?
I'm not sure if I clearly understand the meaning of "precedence" here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this could be clarified better. I was trying to say foo: bar should be given precedence here since it appears first in the list. That means that foo: bar1 would not match (unless type was "Prefix").

Copy link
Contributor

Choose a reason for hiding this comment

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

This is in conflict with the general rule, which is "multiple match values are ANDed". So I'm not sure that we need to add the complexity of a special case for duplicates (as a quality of implementation issue, maybe validation could reject this case or a controller could emit a warning).

Copy link
Member Author

Choose a reason for hiding this comment

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

so in the above example no requests should match because the result of an AND here would always be false?

Copy link
Contributor

Choose a reason for hiding this comment

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

so in the above example no requests should match because the result of an AND here would always be false?

Yup, exactly.

Copy link
Member Author

@robscott robscott May 14, 2021

Choose a reason for hiding this comment

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

There's a lot of nuance here and it's difficult to get the wording right. For example, the following would be valid:

- name: foo
  type: RegularExpression
  value: [a-z]
- name: Foo
  type: RegularExpression
  value: [a-z0-9]

It may not actually make any sense to configure a Route that way, but a value like z would be valid. And similar ambiguity would likely also exist for ImplementationSpecific match types. So the only thing we can say for sure is the following:

Specifying different values with an exact match type for equivalent header names will not match any requests.

And once I took the time to write that out, it seemed obvious, so I just omitted it. Maybe providing the specific example you suggested would be a better way to explain this than the sentence I have above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added an example here that I think helps explain how this should be interpreted.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually given the regex example, we should just say if you repeat items with the same name, it will be "implementation specific" how this is implemented. Some infra may not support AND'ing regex together -- and ANDing regex is not an operator that is easy to do with a regex.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point that ANDing a regex is simply not a practical expectation here. Instead of falling back to implementation specific handling of this, I think it may make the most sense simply to revert back to something resembling the original approach. Specifying that implementations must ignore subsequent matches for equivalent names and only implement the first one should be relatively easy to implement for everyone and results in a consistent experience.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 makes sense, this is both easy to implement and consistent for users.

@stevesloka
Copy link
Contributor

lgtm with @hbagdi's comments. =)

apis/v1alpha2/httproute_types.go Show resolved Hide resolved
apis/v1alpha2/httproute_types.go Outdated Show resolved Hide resolved
@jpeach
Copy link
Contributor

jpeach commented May 13, 2021 via email

@robscott robscott force-pushed the header-query-match-lists branch from 704fe62 to 971a172 Compare May 13, 2021 23:54
@robscott robscott force-pushed the header-query-match-lists branch 2 times, most recently from b8736b7 to 6121abf Compare May 14, 2021 18:27
hbagdi added a commit to hbagdi/service-apis that referenced this pull request May 17, 2021
This was found during manual testing for kubernetes-sigs#657:

```
$ kubectl apply -f examples | wc
     38      76    1989
$ kubectl apply --recursive -f examples | wc
     47      94    2424
```
@hbagdi
Copy link
Contributor

hbagdi commented May 17, 2021

I found a bug in our verify script and opened up #670 to fix it.
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 17, 2021
@hbagdi
Copy link
Contributor

hbagdi commented May 17, 2021

@robscott It seems the examples didn't pass validation, I'm not sure why they failed. Could you rebase on the latest HEAD on our dev branch?

This matches the API conventions that prefer lists of named subobjects
over maps.
@robscott robscott force-pushed the header-query-match-lists branch from 6121abf to e2af0bf Compare May 17, 2021 21:20
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 17, 2021
@robscott
Copy link
Member Author

@hbagdi it was actually a great catch - I had Name as the json field name instead of name. Should be fixed now.

@hbagdi
Copy link
Contributor

hbagdi commented May 17, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 17, 2021
@k8s-ci-robot k8s-ci-robot merged commit cb48d36 into kubernetes-sigs:master May 17, 2021
@robscott robscott deleted the header-query-match-lists branch January 8, 2022 01:04
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. breaking-change 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/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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants