Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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:
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ grpcRoutes:
- method:
service: com.[A-Z]+
type: RegularExpression
name: grpcrule-1
status:
parents:
- conditions:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion internal/gatewayapi/testdata/httproute-with-metadata.in.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 34 additions & 0 deletions internal/gatewayapi/testdata/httproute-with-metadata.out.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -130,4 +163,5 @@ xdsIR:
kind: HTTPRoute
name: httproute-1
namespace: default
sectionName: rule-1
name: httproute/default/httproute-1/rule/0/match/-1/*