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

Adding QueryParam matching to HTTPRoute #631

Merged
merged 1 commit into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions apis/v1alpha1/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,23 @@ const (
HeaderMatchImplementationSpecific HeaderMatchType = "ImplementationSpecific"
)

// QueryParamMatchType specifies the semantics of how HTTP query parameter
// values should be compared. Valid QueryParamMatchType values are:
//
// * "Exact"
// * "RegularExpression"
// * "ImplementationSpecific"
//
// +kubebuilder:validation:Enum=Exact;RegularExpression;ImplementationSpecific
type QueryParamMatchType string

// QueryParamMatchType constants.
const (
QueryParamMatchExact QueryParamMatchType = "Exact"
Copy link
Contributor

@jpeach jpeach Apr 28, 2021

Choose a reason for hiding this comment

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

These need godoc comments for the generated API reference.

QueryParamMatchRegularExpression QueryParamMatchType = "RegularExpression"
QueryParamMatchImplementationSpecific QueryParamMatchType = "ImplementationSpecific"
)

// HTTPPathMatch describes how to select a HTTP route by matching the HTTP request path.
type HTTPPathMatch struct {
// Type specifies how to match against the path Value.
Expand Down Expand Up @@ -326,6 +343,38 @@ type HTTPHeaderMatch struct {
Values map[string]string `json:"values"`
}

// HTTPQueryParamMatch describes how to select a HTTP route by matching HTTP
// query parameters.
type HTTPQueryParamMatch struct {
// Type specifies how to match against the value of the query parameter.
//
// Support: Extended (Exact)
//
// Support: Custom (RegularExpression, ImplementationSpecific)
//
// Since RegularExpression QueryParamMatchType has custom conformance,
// implementations can support POSIX, PCRE or any other dialects of regular
// expressions. Please read the implementation's documentation to determine
// the supported dialect.
//
// HTTP query parameter matching MUST be case-sensitive for both keys and
// values.
//
// +optional
// +kubebuilder:default=Exact
Type *QueryParamMatchType `json:"type,omitempty"`

// Values is a map of HTTP query parameters to be matched. It MUST contain
// at least one entry.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: If this must contain at least one entry, should we set the validation minimum?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately it does not look like it's possible to validate that with annotations. It does seem like something we should catch with the webhook though (for both this and header matching).

//
// The query parameter name to match is the map key, and the value of the
// query parameter is the map value.
//
// Multiple match values are ANDed together, meaning, a request must match
// all the specified query parameters to select the route.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I feel like we should be clear that, even if you specify one of the ImplementationSpecific matches, we shouldn't allow regexes or other craziness in the query param name, just the value?

Something like:

Suggested change
// all the specified query parameters to select the route.
// all the specified query parameters to select the route.
//
// Note that the query param type matching MUST only be used for the query param value, not the query param name.

Copy link
Contributor

Choose a reason for hiding this comment

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

More direct would be (don't refer to param matching type to avoid indirection):

Query parameter key is must be an exact match (string comparison).

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 call, added in #636

Values map[string]string `json:"values"`
}

// HTTPRouteMatch defines the predicate used to match requests to a given
// action. Multiple match types are ANDed together, i.e. the match will
// evaluate to true only if all conditions are satisfied.
Expand Down Expand Up @@ -354,6 +403,11 @@ type HTTPRouteMatch struct {
// +optional
Headers *HTTPHeaderMatch `json:"headers,omitempty"`

// QueryParams specifies a HTTP query parameter matcher.
//
// +optional
QueryParams *HTTPQueryParamMatch `json:"queryParams,omitempty"`

// ExtensionRef is an optional, implementation-specific extension to the
// "match" behavior. For example, resource "myroutematcher" in group
// "networking.acme.io". If the referent cannot be found, the rule is not
Expand Down
32 changes: 32 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions config/crd/bases/networking.x-k8s.io_httproutes.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/basic-http.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
type: Exact
values:
magic: foo
queryParams:
type: Exact
values:
great: example
path:
type: Prefix
value: /some/thing
Expand Down