From 809bf1deb83a7ebbb3f66074122ea113174b24cf Mon Sep 17 00:00:00 2001 From: Iryna Shustava Date: Fri, 20 Oct 2023 16:59:18 -0600 Subject: [PATCH] mesh: ensure route configs are named uniquely per port (#19323) --- .../sidecarproxy/builder/destinations.go | 2 +- .../controllers/sidecarproxy/builder/naming.go | 6 +++--- ...-multiple-implicit-destinations-tproxy.golden | 16 ++++++++-------- ...-l7-single-implicit-destination-tproxy.golden | 6 +++--- ...ination-with-multiple-workloads-tproxy.golden | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/internal/mesh/internal/controllers/sidecarproxy/builder/destinations.go b/internal/mesh/internal/controllers/sidecarproxy/builder/destinations.go index 56b032697c..6031d72cfd 100644 --- a/internal/mesh/internal/controllers/sidecarproxy/builder/destinations.go +++ b/internal/mesh/internal/controllers/sidecarproxy/builder/destinations.go @@ -94,7 +94,7 @@ func (b *Builder) buildDestination( if destination.Explicit != nil { routeName = lb.listener.Name } else { - routeName = DestinationResourceID(cpr.ParentRef.Ref) + routeName = DestinationResourceID(cpr.ParentRef.Ref, cpr.ParentRef.Port) } var ( diff --git a/internal/mesh/internal/controllers/sidecarproxy/builder/naming.go b/internal/mesh/internal/controllers/sidecarproxy/builder/naming.go index 31eba2e7ce..13a21e4e59 100644 --- a/internal/mesh/internal/controllers/sidecarproxy/builder/naming.go +++ b/internal/mesh/internal/controllers/sidecarproxy/builder/naming.go @@ -29,7 +29,7 @@ func DestinationStatPrefix(serviceRef *pbresource.Reference, portName, datacente } func DestinationListenerName(destinationRef *pbresource.Reference, portName string, address string, port uint32) string { - name := fmt.Sprintf("%s:%s:%s", DestinationResourceID(destinationRef), portName, address) + name := fmt.Sprintf("%s:%s", DestinationResourceID(destinationRef, portName), address) if port != 0 { return fmt.Sprintf("%s:%d", name, port) } @@ -39,8 +39,8 @@ func DestinationListenerName(destinationRef *pbresource.Reference, portName stri // DestinationResourceID returns a string representation that uniquely identifies the // upstream in a canonical but human readable way. -func DestinationResourceID(destinationRef *pbresource.Reference) string { +func DestinationResourceID(destinationRef *pbresource.Reference, port string) string { tenancyPrefix := fmt.Sprintf("%s/%s/%s", destinationRef.Tenancy.Partition, destinationRef.Tenancy.PeerName, destinationRef.Tenancy.Namespace) - return fmt.Sprintf("%s/%s", tenancyPrefix, destinationRef.Name) + return fmt.Sprintf("%s/%s:%s", tenancyPrefix, destinationRef.Name, port) } diff --git a/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/destination/multiport-l4-and-l7-multiple-implicit-destinations-tproxy.golden b/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/destination/multiport-l4-and-l7-multiple-implicit-destinations-tproxy.golden index fb9b8a52ea..57fa51a81a 100644 --- a/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/destination/multiport-l4-and-l7-multiple-implicit-destinations-tproxy.golden +++ b/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/destination/multiport-l4-and-l7-multiple-implicit-destinations-tproxy.golden @@ -248,7 +248,7 @@ { "l7": { "route": { - "name": "default/local/default/api-app" + "name": "default/local/default/api-app:http" }, "statPrefix": "upstream." }, @@ -265,7 +265,7 @@ { "l7": { "route": { - "name": "default/local/default/api-app2" + "name": "default/local/default/api-app2:http" }, "statPrefix": "upstream." }, @@ -325,18 +325,18 @@ } ], "routes": { - "default/local/default/api-app": { + "default/local/default/api-app2:http": { "virtualHosts": [ { "domains": [ "*" ], - "name": "default/local/default/api-app", + "name": "default/local/default/api-app2:http", "routeRules": [ { "destination": { "cluster": { - "name": "http.api-app.default.dc1.internal.foo.consul" + "name": "http.api-app2.default.dc1.internal.foo.consul" } }, "match": { @@ -349,18 +349,18 @@ } ] }, - "default/local/default/api-app2": { + "default/local/default/api-app:http": { "virtualHosts": [ { "domains": [ "*" ], - "name": "default/local/default/api-app2", + "name": "default/local/default/api-app:http", "routeRules": [ { "destination": { "cluster": { - "name": "http.api-app2.default.dc1.internal.foo.consul" + "name": "http.api-app.default.dc1.internal.foo.consul" } }, "match": { diff --git a/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/destination/multiport-l4-and-l7-single-implicit-destination-tproxy.golden b/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/destination/multiport-l4-and-l7-single-implicit-destination-tproxy.golden index e29403f0f8..f53a79caa6 100644 --- a/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/destination/multiport-l4-and-l7-single-implicit-destination-tproxy.golden +++ b/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/destination/multiport-l4-and-l7-single-implicit-destination-tproxy.golden @@ -146,7 +146,7 @@ { "l7": { "route": { - "name": "default/local/default/api-app" + "name": "default/local/default/api-app:http" }, "statPrefix": "upstream." }, @@ -181,13 +181,13 @@ } ], "routes": { - "default/local/default/api-app": { + "default/local/default/api-app:http": { "virtualHosts": [ { "domains": [ "*" ], - "name": "default/local/default/api-app", + "name": "default/local/default/api-app:http", "routeRules": [ { "destination": { diff --git a/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/destination/multiport-l4-and-l7-single-implicit-destination-with-multiple-workloads-tproxy.golden b/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/destination/multiport-l4-and-l7-single-implicit-destination-with-multiple-workloads-tproxy.golden index e29403f0f8..f53a79caa6 100644 --- a/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/destination/multiport-l4-and-l7-single-implicit-destination-with-multiple-workloads-tproxy.golden +++ b/internal/mesh/internal/controllers/sidecarproxy/builder/testdata/destination/multiport-l4-and-l7-single-implicit-destination-with-multiple-workloads-tproxy.golden @@ -146,7 +146,7 @@ { "l7": { "route": { - "name": "default/local/default/api-app" + "name": "default/local/default/api-app:http" }, "statPrefix": "upstream." }, @@ -181,13 +181,13 @@ } ], "routes": { - "default/local/default/api-app": { + "default/local/default/api-app:http": { "virtualHosts": [ { "domains": [ "*" ], - "name": "default/local/default/api-app", + "name": "default/local/default/api-app:http", "routeRules": [ { "destination": {