Skip to content

Commit

Permalink
xds route metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Guy Daich <[email protected]>
  • Loading branch information
guydc committed Jun 13, 2024
1 parent 845a5ec commit 5cb74a5
Show file tree
Hide file tree
Showing 189 changed files with 2,011 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,13 @@ xds:
routes:
- match:
prefix: /
metadata:
filterMetadata:
io.envoyproxy.gateway.metadata:
groupVersion: ""
kind: HTTPRoute
name: backend
namespace: default
name: httproute/default/backend/rule/0/match/0/www_example_com
route:
cluster: httproute/default/backend/rule/0
Expand All @@ -1098,6 +1105,13 @@ xds:
routes:
- match:
path: /com.example.Things/DoThing
metadata:
filterMetadata:
io.envoyproxy.gateway.metadata:
groupVersion: ""
kind: GRPCRoute
name: backend
namespace: default
name: grpcroute/default/backend/rule/0/match/0/www_grpc-example_com
route:
cluster: grpcroute/default/backend/rule/0
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,16 @@
"match": {
"prefix": "/"
},
"metadata": {
"filterMetadata": {
"io.envoyproxy.gateway.metadata": {
"groupVersion": "",
"kind": "HTTPRoute",
"name": "backend",
"namespace": "default"
}
}
},
"name": "httproute/default/backend/rule/0/match/0/www_example_com",
"route": {
"cluster": "httproute/default/backend/rule/0",
Expand Down Expand Up @@ -1002,6 +1012,16 @@
"match": {
"path": "/com.example.Things/DoThing"
},
"metadata": {
"filterMetadata": {
"io.envoyproxy.gateway.metadata": {
"groupVersion": "",
"kind": "GRPCRoute",
"name": "backend",
"namespace": "default"
}
}
},
"name": "grpcroute/default/backend/rule/0/match/0/www_grpc-example_com",
"route": {
"cluster": "grpcroute/default/backend/rule/0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,13 @@ xds:
routes:
- match:
prefix: /
metadata:
filterMetadata:
io.envoyproxy.gateway.metadata:
groupVersion: ""
kind: HTTPRoute
name: backend
namespace: default
name: httproute/default/backend/rule/0/match/0/www_example_com
route:
cluster: httproute/default/backend/rule/0
Expand All @@ -594,6 +601,13 @@ xds:
routes:
- match:
path: /com.example.Things/DoThing
metadata:
filterMetadata:
io.envoyproxy.gateway.metadata:
groupVersion: ""
kind: GRPCRoute
name: backend
namespace: default
name: grpcroute/default/backend/rule/0/match/0/www_grpc-example_com
route:
cluster: grpcroute/default/backend/rule/0
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ xds:
routes:
- match:
prefix: /
metadata:
filterMetadata:
io.envoyproxy.gateway.metadata:
groupVersion: ""
kind: HTTPRoute
name: backend
namespace: default
name: httproute/default/backend/rule/0/match/0/www_example_com
route:
cluster: httproute/default/backend/rule/0
Expand All @@ -29,6 +36,13 @@ xds:
routes:
- match:
path: /com.example.Things/DoThing
metadata:
filterMetadata:
io.envoyproxy.gateway.metadata:
groupVersion: ""
kind: GRPCRoute
name: backend
namespace: default
name: grpcroute/default/backend/rule/0/match/0/www_grpc-example_com
route:
cluster: grpcroute/default/backend/rule/0
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,16 @@
"match": {
"pathSeparatedPrefix": "/foo"
},
"metadata": {
"filterMetadata": {
"io.envoyproxy.gateway.metadata": {
"groupVersion": "",
"kind": "HTTPRoute",
"name": "backend",
"namespace": "envoy-gateway-system"
}
}
},
"name": "httproute/envoy-gateway-system/backend/rule/0/match/0/www_example_com",
"route": {
"cluster": "httproute/envoy-gateway-system/backend/rule/0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ xds:
routes:
- match:
pathSeparatedPrefix: /foo
metadata:
filterMetadata:
io.envoyproxy.gateway.metadata:
groupVersion: ""
kind: HTTPRoute
name: backend
namespace: envoy-gateway-system
name: httproute/envoy-gateway-system/backend/rule/0/match/0/www_example_com
route:
cluster: httproute/envoy-gateway-system/backend/rule/0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ xds:
routes:
- match:
pathSeparatedPrefix: /foo
metadata:
filterMetadata:
io.envoyproxy.gateway.metadata:
groupVersion: ""
kind: HTTPRoute
name: backend
namespace: envoy-gateway-system
name: httproute/envoy-gateway-system/backend/rule/0/match/0/www_example_com
route:
cluster: httproute/envoy-gateway-system/backend/rule/0
Expand Down
20 changes: 20 additions & 0 deletions internal/cmd/egctl/testdata/translate/out/multiple-xds.route.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
"match": {
"prefix": "/"
},
"metadata": {
"filterMetadata": {
"io.envoyproxy.gateway.metadata": {
"groupVersion": "",
"kind": "HTTPRoute",
"name": "backend",
"namespace": "default"
}
}
},
"name": "httproute/default/backend/rule/0/match/0/www_example_com",
"route": {
"cluster": "httproute/default/backend/rule/0",
Expand Down Expand Up @@ -55,6 +65,16 @@
"match": {
"pathSeparatedPrefix": "/v2"
},
"metadata": {
"filterMetadata": {
"io.envoyproxy.gateway.metadata": {
"groupVersion": "",
"kind": "HTTPRoute",
"name": "backend",
"namespace": "default"
}
}
},
"name": "httproute/default/backend/rule/0/match/0/www_example2_com",
"route": {
"cluster": "httproute/default/backend/rule/0",
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/egctl/testdata/translate/out/quickstart.all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ xdsIR:
weight: 1
hostname: www.example.com
isHTTP2: false
metadata:
kind: HTTPRoute
name: backend
namespace: envoy-gateway-system
name: httproute/envoy-gateway-system/backend/rule/0/match/0/www_example_com
pathMatch:
distinct: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ xds:
routes:
- match:
prefix: /
metadata:
filterMetadata:
io.envoyproxy.gateway.metadata:
groupVersion: ""
kind: HTTPRoute
name: backend
namespace: envoy-gateway-system
name: httproute/envoy-gateway-system/backend/rule/0/match/0/www_example_com
route:
cluster: httproute/envoy-gateway-system/backend/rule/0
Expand Down
27 changes: 27 additions & 0 deletions internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const (
// Request timeout, which is defined as Duration, specifies the upstream timeout for the route
// If not specified, the default is 15s
HTTPRequestTimeout = "15s"
// egPrefix is a prefix of annotation keys that are processed by Envoy Gateway
egPrefix = "gateway.envoyproxy.io/"
)

var (
Expand Down Expand Up @@ -647,6 +649,7 @@ func (t *Translator) processHTTPRouteParentRefListener(route RouteContext, route
continue
}
hasHostnameIntersection = true
routeMetadata := buildRouteMetadata(route)

var perHostRoutes []*ir.HTTPRoute
for _, host := range hosts {
Expand All @@ -673,6 +676,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,
Hostname: host,
PathMatch: routeRoute.PathMatch,
HeaderMatches: routeRoute.HeaderMatches,
Expand Down Expand Up @@ -712,6 +716,29 @@ func (t *Translator) processHTTPRouteParentRefListener(route RouteContext, route
return hasHostnameIntersection
}

func buildRouteMetadata(route RouteContext) *ir.ResourceMetadata {
return &ir.ResourceMetadata{
Kind: route.GetObjectKind().GroupVersionKind().Kind,
GroupVersion: route.GetObjectKind().GroupVersionKind().GroupVersion().String(),
Name: route.GetName(),
Namespace: route.GetNamespace(),
Annotations: filterEGPrefix(route.GetAnnotations()),
}
}

func filterEGPrefix(in map[string]string) map[string]string {
out := map[string]string{}
for k, v := range in {
if strings.HasPrefix(k, egPrefix) {
out[strings.TrimPrefix(k, egPrefix)] = v
}
}
if len(out) == 0 {
return nil
}
return out
}

func (t *Translator) ProcessTLSRoutes(tlsRoutes []*gwapiv1a2.TLSRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*TLSRouteContext {
var relevantTLSRoutes []*TLSRouteContext

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ xdsIR:
statusCode: 500
hostname: '*'
isHTTP2: false
metadata:
groupVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
name: httproute-1
namespace: default
name: httproute/default/httproute-1/rule/0/match/0/*
pathMatch:
distinct: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ xdsIR:
weight: 1
hostname: '*'
isHTTP2: false
metadata:
groupVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
name: httproute-btls
namespace: envoy-gateway
name: httproute/envoy-gateway/httproute-btls/rule/0/match/0/*
pathMatch:
distinct: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ xdsIR:
weight: 1
hostname: '*'
isHTTP2: false
metadata:
groupVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
name: httproute-btls
namespace: envoy-gateway
name: httproute/envoy-gateway/httproute-btls/rule/0/match/0/*
pathMatch:
distinct: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ xdsIR:
weight: 1
hostname: '*'
isHTTP2: false
metadata:
groupVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
name: httproute-btls
namespace: envoy-gateway
name: httproute/envoy-gateway/httproute-btls/rule/0/match/0/*
pathMatch:
distinct: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ xdsIR:
weight: 1
hostname: '*'
isHTTP2: false
metadata:
groupVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
name: httproute-btls
namespace: envoy-gateway
name: httproute/envoy-gateway/httproute-btls/rule/0/match/0/*
pathMatch:
distinct: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ xdsIR:
weight: 1
hostname: '*'
isHTTP2: false
metadata:
groupVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
name: httproute-btls
namespace: envoy-gateway
name: httproute/envoy-gateway/httproute-btls/rule/0/match/0/*
pathMatch:
distinct: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ xdsIR:
weight: 1
hostname: '*'
isHTTP2: false
metadata:
groupVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
name: httproute-btls
namespace: envoy-gateway
name: httproute/envoy-gateway/httproute-btls/rule/0/match/0/*
pathMatch:
distinct: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ xdsIR:
weight: 1
hostname: '*'
isHTTP2: true
metadata:
groupVersion: gateway.networking.k8s.io/v1alpha2
kind: GRPCRoute
name: grpcroute-1
namespace: default
name: grpcroute/default/grpcroute-1/rule/0/match/-1/*
traffic:
timeout:
Expand Down Expand Up @@ -304,6 +309,11 @@ xdsIR:
weight: 1
hostname: gateway.envoyproxy.io
isHTTP2: false
metadata:
groupVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
name: httproute-1
namespace: default
name: httproute/default/httproute-1/rule/0/match/0/gateway_envoyproxy_io
pathMatch:
distinct: false
Expand Down
Loading

0 comments on commit 5cb74a5

Please sign in to comment.