Skip to content

Commit

Permalink
Adding QueryParam matching to HTTPRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
robscott committed Apr 23, 2021
1 parent a122b1f commit bbe08db
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
55 changes: 55 additions & 0 deletions apis/v1alpha1/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,25 @@ const (
HeaderMatchImplementationSpecific HeaderMatchType = "ImplementationSpecific"
)

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

// QueryParamMatchType constants.
const (
QueryParamMatchExact HeaderMatchType = "Exact"
QueryParamMatchPresence HeaderMatchType = "Presence"
QueryParamMatchRegularExpression HeaderMatchType = "RegularExpression"
QueryParamMatchImplementationSpecific HeaderMatchType = "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 +345,37 @@ 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, Presence)
//
// Support: Custom (RegularExpression, ImplementationSpecific)
//
// Since RegularExpression PathType 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.
//
// +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.
//
// 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.
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 +404,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

0 comments on commit bbe08db

Please sign in to comment.