diff --git a/controller/pkg/agentgateway/translator/agw.go b/controller/pkg/agentgateway/translator/agw.go index 33c65c2b0..3598d0072 100644 --- a/controller/pkg/agentgateway/translator/agw.go +++ b/controller/pkg/agentgateway/translator/agw.go @@ -67,13 +67,17 @@ func CreateAgwPathMatch(match gwv1.HTTPRouteMatch) (*api.PathMatch, *reporter.Ro if match.Path.Type != nil { tp = *match.Path.Type } - // Path value must start with "/". If empty/nil, coerce to "/". + // For non-regex path match types, ensure the path starts with "/". + // If the value is empty or nil, default to "/". + // RegularExpression paths are not modified to support full regex patterns (e.g. "^/.*$"). dest := "/" if match.Path.Value != nil && *match.Path.Value != "" { dest = *match.Path.Value } - if !strings.HasPrefix(dest, "/") { - dest = "/" + dest + if tp != gwv1.PathMatchRegularExpression { + if !strings.HasPrefix(dest, "/") { + dest = "/" + dest + } } switch tp { case gwv1.PathMatchPathPrefix: diff --git a/controller/pkg/agentgateway/translator/testdata/routes/httproute-path-prefix-regex.yaml b/controller/pkg/agentgateway/translator/testdata/routes/httproute-path-prefix-regex.yaml new file mode 100644 index 000000000..c5b735d7b --- /dev/null +++ b/controller/pkg/agentgateway/translator/testdata/routes/httproute-path-prefix-regex.yaml @@ -0,0 +1,70 @@ +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: regex-route + namespace: default +spec: + parentRefs: + - name: test-gateway + hostnames: + - example.com + rules: + - matches: + - path: + type: RegularExpression + value: ^/.*$ + backendRefs: + - name: test-service + port: 80 +--- +# Output +output: +- gateway: + Name: test-gateway + Namespace: default + resource: + route: + backends: + - backend: + port: 80 + service: + hostname: test-service.default.svc.cluster.local + namespace: default + weight: 1 + hostnames: + - example.com + key: default/regex-route.00.http + listenerKey: default/test-gateway.http + matches: + - path: + regex: ^/.*$ + name: + kind: HTTPRoute + name: regex-route + namespace: default +status: +- apiVersion: gateway.networking.k8s.io/v1 + kind: HTTPRoute + metadata: + name: regex-route + namespace: default + spec: null + status: + parents: + - conditions: + - lastTransitionTime: fake + message: "" + reason: Accepted + status: "True" + type: Accepted + - lastTransitionTime: fake + message: "" + reason: ResolvedRefs + status: "True" + type: ResolvedRefs + controllerName: agentgateway.dev/agentgateway + parentRef: + group: gateway.networking.k8s.io + kind: Gateway + name: test-gateway + namespace: default