diff --git a/internal/gatewayapi/route.go b/internal/gatewayapi/route.go index e51947411d8..26627a07285 100644 --- a/internal/gatewayapi/route.go +++ b/internal/gatewayapi/route.go @@ -302,6 +302,7 @@ func (t *Translator) processHTTPRouteRule(httpRoute *HTTPRouteContext, ruleIdx i irRoute := &ir.HTTPRoute{ Name: irRouteName(httpRoute, ruleIdx, -1), } + irRoute.Metadata = buildRouteMetadata(httpRoute, rule.Name) processRouteTimeout(irRoute, rule) applyHTTPFiltersContextToIRRoute(httpFiltersContext, irRoute) ruleRoutes = append(ruleRoutes, irRoute) @@ -362,6 +363,7 @@ func (t *Translator) processHTTPRouteRule(httpRoute *HTTPRouteContext, ruleIdx i Name: irRouteName(httpRoute, ruleIdx, matchIdx), SessionPersistence: sessionPersistence, } + irRoute.Metadata = buildRouteMetadata(httpRoute, rule.Name) processRouteTimeout(irRoute, rule) if match.Path != nil { @@ -595,6 +597,7 @@ func (t *Translator) processGRPCRouteRule(grpcRoute *GRPCRouteContext, ruleIdx i irRoute := &ir.HTTPRoute{ Name: irRouteName(grpcRoute, ruleIdx, -1), } + irRoute.Metadata = buildRouteMetadata(grpcRoute, rule.Name) applyHTTPFiltersContextToIRRoute(httpFiltersContext, irRoute) ruleRoutes = append(ruleRoutes, irRoute) } @@ -606,7 +609,7 @@ func (t *Translator) processGRPCRouteRule(grpcRoute *GRPCRouteContext, ruleIdx i irRoute := &ir.HTTPRoute{ Name: irRouteName(grpcRoute, ruleIdx, matchIdx), } - + irRoute.Metadata = buildRouteMetadata(grpcRoute, rule.Name) for _, headerMatch := range match.Headers { switch GRPCHeaderMatchTypeDerefOr(headerMatch.Type, gwapiv1.GRPCHeaderMatchExact) { case gwapiv1.GRPCHeaderMatchExact: @@ -696,7 +699,6 @@ func (t *Translator) processHTTPRouteParentRefListener(route RouteContext, route continue } hasHostnameIntersection = true - routeMetadata := buildRouteMetadata(route) var perHostRoutes []*ir.HTTPRoute for _, host := range hosts { @@ -723,7 +725,7 @@ func (t *Translator) processHTTPRouteParentRefListener(route RouteContext, route underscoredHost := strings.ReplaceAll(host, ".", "_") hostRoute := &ir.HTTPRoute{ Name: fmt.Sprintf("%s/%s", routeRoute.Name, underscoredHost), - Metadata: routeMetadata, + Metadata: routeRoute.Metadata, Hostname: host, PathMatch: routeRoute.PathMatch, HeaderMatches: routeRoute.HeaderMatches, @@ -764,13 +766,17 @@ func (t *Translator) processHTTPRouteParentRefListener(route RouteContext, route return hasHostnameIntersection } -func buildRouteMetadata(route RouteContext) *ir.ResourceMetadata { - return &ir.ResourceMetadata{ +func buildRouteMetadata(route RouteContext, sectionName *gwapiv1.SectionName) *ir.ResourceMetadata { + metadata := &ir.ResourceMetadata{ Kind: route.GetObjectKind().GroupVersionKind().Kind, Name: route.GetName(), Namespace: route.GetNamespace(), Annotations: filterEGPrefix(route.GetAnnotations()), } + if sectionName != nil { + metadata.SectionName = string(*sectionName) + } + return metadata } func filterEGPrefix(in map[string]string) map[string]string { diff --git a/internal/gatewayapi/testdata/grpcroute-with-backend.in.yaml b/internal/gatewayapi/testdata/grpcroute-with-backend.in.yaml index a02496321ec..d4fec0ea572 100644 --- a/internal/gatewayapi/testdata/grpcroute-with-backend.in.yaml +++ b/internal/gatewayapi/testdata/grpcroute-with-backend.in.yaml @@ -36,6 +36,7 @@ grpcRoutes: - group: gateway.envoyproxy.io kind: Backend name: backend-ip + name: grpcrule-1 backends: - apiVersion: gateway.envoyproxy.io/v1alpha1 kind: Backend diff --git a/internal/gatewayapi/testdata/grpcroute-with-backend.out.yaml b/internal/gatewayapi/testdata/grpcroute-with-backend.out.yaml index ba9f13c3136..8981d87b085 100644 --- a/internal/gatewayapi/testdata/grpcroute-with-backend.out.yaml +++ b/internal/gatewayapi/testdata/grpcroute-with-backend.out.yaml @@ -82,6 +82,7 @@ grpcRoutes: - method: service: com.[A-Z]+ type: RegularExpression + name: grpcrule-1 status: parents: - conditions: @@ -150,6 +151,7 @@ xdsIR: kind: GRPCRoute name: grpcroute-1 namespace: default + sectionName: grpcrule-1 name: grpcroute/default/grpcroute-1/rule/0/match/1/* pathMatch: distinct: false @@ -167,6 +169,7 @@ xdsIR: kind: GRPCRoute name: grpcroute-1 namespace: default + sectionName: grpcrule-1 name: grpcroute/default/grpcroute-1/rule/0/match/0/* pathMatch: distinct: false diff --git a/internal/gatewayapi/testdata/httproute-with-metadata.in.yaml b/internal/gatewayapi/testdata/httproute-with-metadata.in.yaml index 24f9fa568ad..c215c01004c 100644 --- a/internal/gatewayapi/testdata/httproute-with-metadata.in.yaml +++ b/internal/gatewayapi/testdata/httproute-with-metadata.in.yaml @@ -31,4 +31,13 @@ httpRoutes: - backendRefs: - name: service-1 port: 8080 - + name: rule-1 + - backendRefs: + - name: service-1 + port: 8080 + matches: + - headers: + - type: Exact + name: foo + value: bar + name: rule-2 diff --git a/internal/gatewayapi/testdata/httproute-with-metadata.out.yaml b/internal/gatewayapi/testdata/httproute-with-metadata.out.yaml index 8d86bec237a..9049ebe41de 100644 --- a/internal/gatewayapi/testdata/httproute-with-metadata.out.yaml +++ b/internal/gatewayapi/testdata/httproute-with-metadata.out.yaml @@ -58,6 +58,16 @@ httpRoutes: - backendRefs: - name: service-1 port: 8080 + name: rule-1 + - backendRefs: + - name: service-1 + port: 8080 + matches: + - headers: + - name: foo + type: Exact + value: bar + name: rule-2 status: parents: - conditions: @@ -113,6 +123,29 @@ xdsIR: mergeSlashes: true port: 10080 routes: + - destination: + name: httproute/default/httproute-1/rule/1 + settings: + - addressType: IP + endpoints: + - host: 7.7.7.7 + port: 8080 + protocol: HTTP + weight: 1 + headerMatches: + - distinct: false + exact: bar + name: foo + hostname: '*' + isHTTP2: false + metadata: + annotations: + foo: bar + kind: HTTPRoute + name: httproute-1 + namespace: default + sectionName: rule-2 + name: httproute/default/httproute-1/rule/1/match/0/* - destination: name: httproute/default/httproute-1/rule/0 settings: @@ -130,4 +163,5 @@ xdsIR: kind: HTTPRoute name: httproute-1 namespace: default + sectionName: rule-1 name: httproute/default/httproute-1/rule/0/match/-1/*