diff --git a/docs/content/routing/providers/kubernetes-gateway.md b/docs/content/routing/providers/kubernetes-gateway.md index 6a5c52c2d..920a6ccf6 100644 --- a/docs/content/routing/providers/kubernetes-gateway.md +++ b/docs/content/routing/providers/kubernetes-gateway.md @@ -273,7 +273,7 @@ Kubernetes cluster before creating `HTTPRoute` objects. | [6] | `rules` | A list of HTTP matchers, filters and actions. | | [7] | `matches` | Conditions used for matching the rule against incoming HTTP requests. Each match is independent, i.e. this rule will be matched if **any** one of the matches is satisfied. | | [8] | `path` | An HTTP request path matcher. If this field is not specified, a default prefix match on the "/" path is provided. | -| [9] | `type` | Type of match against the path Value (supported types: `Exact`, `PathPrefix`). | +| [9] | `type` | Type of match against the path Value (supported types: `Exact`, `PathPrefix`, and `RegularExpression`). | | [10] | `value` | The value of the HTTP path to match against. | | [11] | `headers` | Conditions to select a HTTP route by matching HTTP request headers. | | [12] | `name` | Name of the HTTP header to be matched. | diff --git a/pkg/provider/kubernetes/gateway/fixtures/httproute/with_several_rules.yml b/pkg/provider/kubernetes/gateway/fixtures/httproute/with_several_rules.yml index 3dc9b9ecf..f1885ec6f 100644 --- a/pkg/provider/kubernetes/gateway/fixtures/httproute/with_several_rules.yml +++ b/pkg/provider/kubernetes/gateway/fixtures/httproute/with_several_rules.yml @@ -68,3 +68,14 @@ spec: weight: 1 kind: Service group: "" + + - matches: + - path: + type: RegularExpression + value: "^/buzz/[0-9]+$" + backendRefs: + - name: whoami + port: 80 + weight: 1 + kind: Service + group: "" diff --git a/pkg/provider/kubernetes/gateway/kubernetes.go b/pkg/provider/kubernetes/gateway/kubernetes.go index ce3c12fe6..2aa5c8df8 100644 --- a/pkg/provider/kubernetes/gateway/kubernetes.go +++ b/pkg/provider/kubernetes/gateway/kubernetes.go @@ -1894,6 +1894,8 @@ func extractRule(routeRule gatev1.HTTPRouteRule, hostRule string) (string, error matchRules = append(matchRules, fmt.Sprintf("Path(`%s`)", *match.Path.Value)) case gatev1.PathMatchPathPrefix: matchRules = append(matchRules, buildPathMatchPathPrefixRule(*match.Path.Value)) + case gatev1.PathMatchRegularExpression: + matchRules = append(matchRules, fmt.Sprintf("PathRegexp(`%s`)", *match.Path.Value)) default: return "", fmt.Errorf("unsupported path match type %s", *match.Path.Type) } diff --git a/pkg/provider/kubernetes/gateway/kubernetes_test.go b/pkg/provider/kubernetes/gateway/kubernetes_test.go index 371ea2251..d83ea3e38 100644 --- a/pkg/provider/kubernetes/gateway/kubernetes_test.go +++ b/pkg/provider/kubernetes/gateway/kubernetes_test.go @@ -1300,6 +1300,12 @@ func TestLoadHTTPRoutes(t *testing.T) { Rule: "Host(`foo.com`) && Path(`/bar`) && Header(`my-header`,`bar`)", RuleSyntax: "v3", }, + "default-http-app-1-my-gateway-web-d23f7039bc8036fb918c": { + EntryPoints: []string{"web"}, + Service: "default-http-app-1-my-gateway-web-d23f7039bc8036fb918c-wrr", + Rule: "Host(`foo.com`) && PathRegexp(`^/buzz/[0-9]+$`)", + RuleSyntax: "v3", + }, }, Middlewares: map[string]*dynamic.Middleware{}, Services: map[string]*dynamic.Service{ @@ -1323,6 +1329,16 @@ func TestLoadHTTPRoutes(t *testing.T) { }, }, }, + "default-http-app-1-my-gateway-web-d23f7039bc8036fb918c-wrr": { + Weighted: &dynamic.WeightedRoundRobin{ + Services: []dynamic.WRRService{ + { + Name: "default-whoami-80", + Weight: func(i int) *int { return &i }(1), + }, + }, + }, + }, "default-whoami-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ Servers: []dynamic.Server{