diff --git a/apis/v1alpha1/httproute_types.go b/apis/v1alpha1/httproute_types.go index 3b47def4f5..0f02b972be 100644 --- a/apis/v1alpha1/httproute_types.go +++ b/apis/v1alpha1/httproute_types.go @@ -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" + 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. @@ -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. + // + // 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. @@ -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 diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index 5f45ecfa56..d157c553d2 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -529,6 +529,33 @@ func (in *HTTPPathMatch) DeepCopy() *HTTPPathMatch { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *HTTPQueryParamMatch) DeepCopyInto(out *HTTPQueryParamMatch) { + *out = *in + if in.Type != nil { + in, out := &in.Type, &out.Type + *out = new(QueryParamMatchType) + **out = **in + } + if in.Values != nil { + in, out := &in.Values, &out.Values + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPQueryParamMatch. +func (in *HTTPQueryParamMatch) DeepCopy() *HTTPQueryParamMatch { + if in == nil { + return nil + } + out := new(HTTPQueryParamMatch) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HTTPRequestHeaderFilter) DeepCopyInto(out *HTTPRequestHeaderFilter) { *out = *in @@ -737,6 +764,11 @@ func (in *HTTPRouteMatch) DeepCopyInto(out *HTTPRouteMatch) { *out = new(HTTPHeaderMatch) (*in).DeepCopyInto(*out) } + if in.QueryParams != nil { + in, out := &in.QueryParams, &out.QueryParams + *out = new(HTTPQueryParamMatch) + (*in).DeepCopyInto(*out) + } if in.ExtensionRef != nil { in, out := &in.ExtensionRef, &out.ExtensionRef *out = new(LocalObjectReference) diff --git a/config/crd/bases/networking.x-k8s.io_httproutes.yaml b/config/crd/bases/networking.x-k8s.io_httproutes.yaml index 51dfca92d9..80c2318132 100644 --- a/config/crd/bases/networking.x-k8s.io_httproutes.yaml +++ b/config/crd/bases/networking.x-k8s.io_httproutes.yaml @@ -726,6 +726,41 @@ spec: description: Value of the HTTP path to match against. type: string type: object + queryParams: + description: QueryParams specifies a HTTP query parameter + matcher. + properties: + type: + default: Exact + description: "Type specifies how to match against + the value of the query parameter. \n Support: Extended + (Exact) \n Support: Custom (RegularExpression, ImplementationSpecific) + \n 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. \n HTTP query parameter + matching MUST be case-sensitive for both keys and + values." + enum: + - Exact + - RegularExpression + - ImplementationSpecific + type: string + values: + additionalProperties: + type: string + description: "Values is a map of HTTP query parameters + to be matched. It MUST contain at least one entry. + \n The query parameter name to match is the map + key, and the value of the query parameter is the + map value. \n Multiple match values are ANDed together, + meaning, a request must match all the specified + query parameters to select the route." + type: object + required: + - values + type: object type: object maxItems: 8 type: array diff --git a/examples/basic-http.yaml b/examples/basic-http.yaml index 9f6568d1b3..2da82db699 100644 --- a/examples/basic-http.yaml +++ b/examples/basic-http.yaml @@ -48,6 +48,10 @@ spec: type: Exact values: magic: foo + queryParams: + type: Exact + values: + great: example path: type: Prefix value: /some/thing