From 5a16a3c3e20d360db61c397634b2939f04288d82 Mon Sep 17 00:00:00 2001 From: Nitya Dhanushkodi Date: Tue, 17 Oct 2023 19:56:53 +0000 Subject: [PATCH 1/2] backport of commit f5491d770745dad727b6891c89c38adfacb04273 --- .../sidecarproxy/builder/expose_paths.go | 19 +++++++++++---- .../testdata/source/l7-expose-paths.golden | 24 +++++++++---------- .../local-and-inbound-connections.golden | 24 +++++++++---------- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/internal/mesh/internal/controllers/sidecarproxy/builder/expose_paths.go b/internal/mesh/internal/controllers/sidecarproxy/builder/expose_paths.go index 6215ab540ca5..0d0c71c0fd2b 100644 --- a/internal/mesh/internal/controllers/sidecarproxy/builder/expose_paths.go +++ b/internal/mesh/internal/controllers/sidecarproxy/builder/expose_paths.go @@ -29,7 +29,7 @@ func (b *Builder) buildExposePaths(workload *pbcatalog.Workload) { } func (b *Builder) addExposePathsListener(workload *pbcatalog.Workload, exposePath *pbmesh.ExposePath) *ListenerBuilder { - listenerName := fmt.Sprintf("exposed_path_%s", exposePathName(exposePath)) + listenerName := exposePathListenerName(exposePath) listener := &pbproxystate.Listener{ Name: listenerName, @@ -44,7 +44,7 @@ func (b *Builder) addExposePathsListener(workload *pbcatalog.Workload, exposePat listener.BindAddress = &pbproxystate.Listener_HostPort{ HostPort: &pbproxystate.HostPortAddress{ Host: meshAddress.Host, - Port: exposePath.LocalPathPort, + Port: exposePath.ListenerPort, }, } @@ -120,12 +120,21 @@ func (b *Builder) addExposePathsRoute(exposePath *pbmesh.ExposePath, clusterName func exposePathName(exposePath *pbmesh.ExposePath) string { r := regexp.MustCompile(`[^a-zA-Z0-9]+`) - return r.ReplaceAllString(exposePath.Path, "") + // The regex removes anything not a letter or number from the path. + path := r.ReplaceAllString(exposePath.Path, "") + return path +} + +func exposePathListenerName(exposePath *pbmesh.ExposePath) string { + // The path could be empty, so the unique name for this exposed path is the path and listener port. + pathPort := fmt.Sprintf("%s%d", exposePathName(exposePath), exposePath.ListenerPort) + listenerName := fmt.Sprintf("exposed_path_%s", pathPort) + return listenerName } func exposePathDestinationName(exposePath *pbmesh.ExposePath) string { - path := exposePathName(exposePath) - return fmt.Sprintf("exposed_path_filter_%s_%d", path, exposePath.ListenerPort) + // The destination of the expose path is to the local port. + return fmt.Sprintf("exposed_path_destination_%s%d", exposePathName(exposePath), exposePath.LocalPathPort) } func exposePathClusterName(exposePath *pbmesh.ExposePath) string { diff --git a/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/l7-expose-paths.golden b/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/l7-expose-paths.golden index df8af168212d..160167e0dbd4 100644 --- a/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/l7-expose-paths.golden +++ b/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/l7-expose-paths.golden @@ -107,16 +107,16 @@ "direction": "DIRECTION_INBOUND", "hostPort": { "host": "10.0.0.1", - "port": 9090 + "port": 1234 }, - "name": "exposed_path_health", + "name": "exposed_path_health1234", "routers": [ { "l7": { "route": { - "name": "exposed_path_filter_health_1234" + "name": "exposed_path_destination_health9090" }, - "statPrefix": "exposed_path_filter_health_1234", + "statPrefix": "exposed_path_destination_health9090", "staticRoute": true } } @@ -126,17 +126,17 @@ "direction": "DIRECTION_INBOUND", "hostPort": { "host": "10.0.0.1", - "port": 9091 + "port": 1235 }, - "name": "exposed_path_GetHealth", + "name": "exposed_path_GetHealth1235", "routers": [ { "l7": { "protocol": "L7_PROTOCOL_HTTP2", "route": { - "name": "exposed_path_filter_GetHealth_1235" + "name": "exposed_path_destination_GetHealth9091" }, - "statPrefix": "exposed_path_filter_GetHealth_1235", + "statPrefix": "exposed_path_destination_GetHealth9091", "staticRoute": true } } @@ -144,13 +144,13 @@ } ], "routes": { - "exposed_path_filter_GetHealth_1235": { + "exposed_path_destination_GetHealth9091": { "virtualHosts": [ { "domains": [ "*" ], - "name": "exposed_path_filter_GetHealth_1235", + "name": "exposed_path_destination_GetHealth9091", "routeRules": [ { "destination": { @@ -168,13 +168,13 @@ } ] }, - "exposed_path_filter_health_1234": { + "exposed_path_destination_health9090": { "virtualHosts": [ { "domains": [ "*" ], - "name": "exposed_path_filter_health_1234", + "name": "exposed_path_destination_health9090", "routeRules": [ { "destination": { diff --git a/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/local-and-inbound-connections.golden b/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/local-and-inbound-connections.golden index 169a4969aefd..498ff8386872 100644 --- a/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/local-and-inbound-connections.golden +++ b/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/local-and-inbound-connections.golden @@ -169,16 +169,16 @@ "direction": "DIRECTION_INBOUND", "hostPort": { "host": "10.0.0.1", - "port": 9090 + "port": 1234 }, - "name": "exposed_path_health", + "name": "exposed_path_health1234", "routers": [ { "l7": { "route": { - "name": "exposed_path_filter_health_1234" + "name": "exposed_path_destination_health9090" }, - "statPrefix": "exposed_path_filter_health_1234", + "statPrefix": "exposed_path_destination_health9090", "staticRoute": true } } @@ -188,17 +188,17 @@ "direction": "DIRECTION_INBOUND", "hostPort": { "host": "10.0.0.1", - "port": 9091 + "port": 1235 }, - "name": "exposed_path_GetHealth", + "name": "exposed_path_GetHealth1235", "routers": [ { "l7": { "protocol": "L7_PROTOCOL_HTTP2", "route": { - "name": "exposed_path_filter_GetHealth_1235" + "name": "exposed_path_destination_GetHealth9091" }, - "statPrefix": "exposed_path_filter_GetHealth_1235", + "statPrefix": "exposed_path_destination_GetHealth9091", "staticRoute": true } } @@ -206,13 +206,13 @@ } ], "routes": { - "exposed_path_filter_GetHealth_1235": { + "exposed_path_destination_GetHealth9091": { "virtualHosts": [ { "domains": [ "*" ], - "name": "exposed_path_filter_GetHealth_1235", + "name": "exposed_path_destination_GetHealth9091", "routeRules": [ { "destination": { @@ -230,13 +230,13 @@ } ] }, - "exposed_path_filter_health_1234": { + "exposed_path_destination_health9090": { "virtualHosts": [ { "domains": [ "*" ], - "name": "exposed_path_filter_health_1234", + "name": "exposed_path_destination_health9090", "routeRules": [ { "destination": { From fd9e737c48e1c8efd015481d1675324f399f2710 Mon Sep 17 00:00:00 2001 From: Nitya Dhanushkodi Date: Tue, 17 Oct 2023 20:29:04 +0000 Subject: [PATCH 2/2] backport of commit 2d4958c309e4bc2844ca7213da16cba2ddff319b --- .../sidecarproxy/builder/expose_paths.go | 11 ++++++----- .../testdata/source/l7-expose-paths.golden | 16 ++++++++-------- .../source/local-and-inbound-connections.golden | 16 ++++++++-------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/internal/mesh/internal/controllers/sidecarproxy/builder/expose_paths.go b/internal/mesh/internal/controllers/sidecarproxy/builder/expose_paths.go index 0d0c71c0fd2b..8ae2033cc5e9 100644 --- a/internal/mesh/internal/controllers/sidecarproxy/builder/expose_paths.go +++ b/internal/mesh/internal/controllers/sidecarproxy/builder/expose_paths.go @@ -55,7 +55,7 @@ func (b *ListenerBuilder) addExposePathsRouter(exposePath *pbmesh.ExposePath) *L if b.listener == nil { return b } - destinationName := exposePathDestinationName(exposePath) + destinationName := exposePathRouteName(exposePath) var l7Protocol pbproxystate.L7Protocol @@ -88,7 +88,7 @@ func (b *ListenerBuilder) addExposePathsRouter(exposePath *pbmesh.ExposePath) *L } func (b *Builder) addExposePathsRoute(exposePath *pbmesh.ExposePath, clusterName string) *Builder { - routeName := exposePathDestinationName(exposePath) + routeName := exposePathRouteName(exposePath) routeRule := &pbproxystate.RouteRule{ Match: &pbproxystate.RouteMatch{ PathMatch: &pbproxystate.PathMatch{ @@ -132,9 +132,10 @@ func exposePathListenerName(exposePath *pbmesh.ExposePath) string { return listenerName } -func exposePathDestinationName(exposePath *pbmesh.ExposePath) string { - // The destination of the expose path is to the local port. - return fmt.Sprintf("exposed_path_destination_%s%d", exposePathName(exposePath), exposePath.LocalPathPort) +func exposePathRouteName(exposePath *pbmesh.ExposePath) string { + // The path could be empty, so the unique name for this exposed path is the path and listener port. + pathPort := fmt.Sprintf("%s%d", exposePathName(exposePath), exposePath.ListenerPort) + return fmt.Sprintf("exposed_path_route_%s", pathPort) } func exposePathClusterName(exposePath *pbmesh.ExposePath) string { diff --git a/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/l7-expose-paths.golden b/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/l7-expose-paths.golden index 160167e0dbd4..2d62699ecfbf 100644 --- a/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/l7-expose-paths.golden +++ b/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/l7-expose-paths.golden @@ -114,9 +114,9 @@ { "l7": { "route": { - "name": "exposed_path_destination_health9090" + "name": "exposed_path_route_health1234" }, - "statPrefix": "exposed_path_destination_health9090", + "statPrefix": "exposed_path_route_health1234", "staticRoute": true } } @@ -134,9 +134,9 @@ "l7": { "protocol": "L7_PROTOCOL_HTTP2", "route": { - "name": "exposed_path_destination_GetHealth9091" + "name": "exposed_path_route_GetHealth1235" }, - "statPrefix": "exposed_path_destination_GetHealth9091", + "statPrefix": "exposed_path_route_GetHealth1235", "staticRoute": true } } @@ -144,13 +144,13 @@ } ], "routes": { - "exposed_path_destination_GetHealth9091": { + "exposed_path_route_GetHealth1235": { "virtualHosts": [ { "domains": [ "*" ], - "name": "exposed_path_destination_GetHealth9091", + "name": "exposed_path_route_GetHealth1235", "routeRules": [ { "destination": { @@ -168,13 +168,13 @@ } ] }, - "exposed_path_destination_health9090": { + "exposed_path_route_health1234": { "virtualHosts": [ { "domains": [ "*" ], - "name": "exposed_path_destination_health9090", + "name": "exposed_path_route_health1234", "routeRules": [ { "destination": { diff --git a/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/local-and-inbound-connections.golden b/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/local-and-inbound-connections.golden index 498ff8386872..77d52fd90b04 100644 --- a/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/local-and-inbound-connections.golden +++ b/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/source/local-and-inbound-connections.golden @@ -176,9 +176,9 @@ { "l7": { "route": { - "name": "exposed_path_destination_health9090" + "name": "exposed_path_route_health1234" }, - "statPrefix": "exposed_path_destination_health9090", + "statPrefix": "exposed_path_route_health1234", "staticRoute": true } } @@ -196,9 +196,9 @@ "l7": { "protocol": "L7_PROTOCOL_HTTP2", "route": { - "name": "exposed_path_destination_GetHealth9091" + "name": "exposed_path_route_GetHealth1235" }, - "statPrefix": "exposed_path_destination_GetHealth9091", + "statPrefix": "exposed_path_route_GetHealth1235", "staticRoute": true } } @@ -206,13 +206,13 @@ } ], "routes": { - "exposed_path_destination_GetHealth9091": { + "exposed_path_route_GetHealth1235": { "virtualHosts": [ { "domains": [ "*" ], - "name": "exposed_path_destination_GetHealth9091", + "name": "exposed_path_route_GetHealth1235", "routeRules": [ { "destination": { @@ -230,13 +230,13 @@ } ] }, - "exposed_path_destination_health9090": { + "exposed_path_route_health1234": { "virtualHosts": [ { "domains": [ "*" ], - "name": "exposed_path_destination_health9090", + "name": "exposed_path_route_health1234", "routeRules": [ { "destination": {