From 91d61af9cf45a2ce016295abff1cefc6edf80c5a Mon Sep 17 00:00:00 2001 From: John Murret Date: Fri, 3 Nov 2023 16:38:37 -0600 Subject: [PATCH 1/6] migrate expose checks and paths tests to resources_test.go --- agent/xds/resources_test.go | 16 +++--- .../endpoints/expose-checks.latest.golden | 24 ++++++++- ...paths-grpc-new-cluster-http1.latest.golden | 24 ++++++++- ...pose-paths-new-cluster-http2.latest.golden | 24 ++++++++- .../listeners/expose-checks.latest.golden | 2 +- .../routes/expose-checks.latest.golden | 27 +++++++++- ...paths-grpc-new-cluster-http1.latest.golden | 50 ++++++++++++++++++- ...expose-paths-local-app-paths.latest.golden | 50 ++++++++++++++++++- ...pose-paths-new-cluster-http2.latest.golden | 50 ++++++++++++++++++- 9 files changed, 249 insertions(+), 18 deletions(-) diff --git a/agent/xds/resources_test.go b/agent/xds/resources_test.go index 13a76ca1d71..61d29209279 100644 --- a/agent/xds/resources_test.go +++ b/agent/xds/resources_test.go @@ -1057,8 +1057,7 @@ func getExposePathGoldenTestCases() []goldenTestCase { create: func(t testinf.T) *proxycfg.ConfigSnapshot { return proxycfg.TestConfigSnapshotExposeConfig(t, nil) }, - // TODO(jm): enable with https://github.com/hashicorp/consul/pull/19459 - alsoRunTestForV2: false, + alsoRunTestForV2: true, }, { name: "downstream-service-with-unix-sockets", @@ -1085,8 +1084,7 @@ func getExposePathGoldenTestCases() []goldenTestCase { } }) }, - // TODO(jm): enable with https://github.com/hashicorp/consul/pull/19459 - alsoRunTestForV2: false, + alsoRunTestForV2: true, }, { name: "expose-checks", @@ -1096,14 +1094,12 @@ func getExposePathGoldenTestCases() []goldenTestCase { return "192.0.2.1" }) }, - // TODO(jm): enable with https://github.com/hashicorp/consul/pull/19459 - alsoRunTestForV2: false, + alsoRunTestForV2: true, }, { - name: "expose-paths-grpc-new-cluster-http1", - create: proxycfg.TestConfigSnapshotGRPCExposeHTTP1, - // TODO(jm): enable with https://github.com/hashicorp/consul/pull/19459 - alsoRunTestForV2: false, + name: "expose-paths-grpc-new-cluster-http1", + create: proxycfg.TestConfigSnapshotGRPCExposeHTTP1, + alsoRunTestForV2: true, }, { // NOTE: if IPv6 is not supported in the kernel per diff --git a/agent/xds/testdata/endpoints/expose-checks.latest.golden b/agent/xds/testdata/endpoints/expose-checks.latest.golden index 96ee5c70946..6efb224f038 100644 --- a/agent/xds/testdata/endpoints/expose-checks.latest.golden +++ b/agent/xds/testdata/endpoints/expose-checks.latest.golden @@ -1,5 +1,27 @@ { "nonce": "00000001", + "resources": [ + { + "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", + "clusterName": "exposed_cluster_8181", + "endpoints": [ + { + "lbEndpoints": [ + { + "endpoint": { + "address": { + "socketAddress": { + "address": "127.0.0.1", + "portValue": 8181 + } + } + } + } + ] + } + ] + } + ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "versionInfo": "00000001" -} \ No newline at end of file +} diff --git a/agent/xds/testdata/endpoints/expose-paths-grpc-new-cluster-http1.latest.golden b/agent/xds/testdata/endpoints/expose-paths-grpc-new-cluster-http1.latest.golden index 96ee5c70946..bd0a8f6255e 100644 --- a/agent/xds/testdata/endpoints/expose-paths-grpc-new-cluster-http1.latest.golden +++ b/agent/xds/testdata/endpoints/expose-paths-grpc-new-cluster-http1.latest.golden @@ -1,5 +1,27 @@ { "nonce": "00000001", + "resources": [ + { + "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", + "clusterName": "exposed_cluster_8090", + "endpoints": [ + { + "lbEndpoints": [ + { + "endpoint": { + "address": { + "socketAddress": { + "address": "127.0.0.1", + "portValue": 8090 + } + } + } + } + ] + } + ] + } + ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "versionInfo": "00000001" -} \ No newline at end of file +} diff --git a/agent/xds/testdata/endpoints/expose-paths-new-cluster-http2.latest.golden b/agent/xds/testdata/endpoints/expose-paths-new-cluster-http2.latest.golden index 96ee5c70946..73d2d630f24 100644 --- a/agent/xds/testdata/endpoints/expose-paths-new-cluster-http2.latest.golden +++ b/agent/xds/testdata/endpoints/expose-paths-new-cluster-http2.latest.golden @@ -1,5 +1,27 @@ { "nonce": "00000001", + "resources": [ + { + "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", + "clusterName": "exposed_cluster_9090", + "endpoints": [ + { + "lbEndpoints": [ + { + "endpoint": { + "address": { + "socketAddress": { + "address": "127.0.0.1", + "portValue": 9090 + } + } + } + } + ] + } + ] + } + ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "versionInfo": "00000001" -} \ No newline at end of file +} diff --git a/agent/xds/testdata/listeners/expose-checks.latest.golden b/agent/xds/testdata/listeners/expose-checks.latest.golden index 2299f061dde..fc378ca7f18 100644 --- a/agent/xds/testdata/listeners/expose-checks.latest.golden +++ b/agent/xds/testdata/listeners/expose-checks.latest.golden @@ -139,4 +139,4 @@ ], "typeUrl": "type.googleapis.com/envoy.config.listener.v3.Listener", "versionInfo": "00000001" -} \ No newline at end of file +} diff --git a/agent/xds/testdata/routes/expose-checks.latest.golden b/agent/xds/testdata/routes/expose-checks.latest.golden index 8b919343d21..2adf5dc233f 100644 --- a/agent/xds/testdata/routes/expose-checks.latest.golden +++ b/agent/xds/testdata/routes/expose-checks.latest.golden @@ -1,5 +1,30 @@ { "nonce": "00000001", + "resources": [ + { + "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", + "name": "exposed_path_filter_debug_21500", + "validateClusters": true, + "virtualHosts": [ + { + "domains": [ + "*" + ], + "name": "exposed_path_filter_debug_21500", + "routes": [ + { + "match": { + "path": "/debug" + }, + "route": { + "cluster": "exposed_cluster_8181" + } + } + ] + } + ] + } + ], "typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", "versionInfo": "00000001" -} \ No newline at end of file +} diff --git a/agent/xds/testdata/routes/expose-paths-grpc-new-cluster-http1.latest.golden b/agent/xds/testdata/routes/expose-paths-grpc-new-cluster-http1.latest.golden index 8b919343d21..5787405ef4d 100644 --- a/agent/xds/testdata/routes/expose-paths-grpc-new-cluster-http1.latest.golden +++ b/agent/xds/testdata/routes/expose-paths-grpc-new-cluster-http1.latest.golden @@ -1,5 +1,53 @@ { "nonce": "00000001", + "resources": [ + { + "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", + "name": "exposed_path_filter_healthz_21500", + "validateClusters": true, + "virtualHosts": [ + { + "domains": [ + "*" + ], + "name": "exposed_path_filter_healthz_21500", + "routes": [ + { + "match": { + "path": "/healthz" + }, + "route": { + "cluster": "exposed_cluster_8090" + } + } + ] + } + ] + }, + { + "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", + "name": "public_listener", + "validateClusters": true, + "virtualHosts": [ + { + "domains": [ + "*" + ], + "name": "public_listener", + "routes": [ + { + "match": { + "prefix": "/" + }, + "route": { + "cluster": "local_app" + } + } + ] + } + ] + } + ], "typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", "versionInfo": "00000001" -} \ No newline at end of file +} diff --git a/agent/xds/testdata/routes/expose-paths-local-app-paths.latest.golden b/agent/xds/testdata/routes/expose-paths-local-app-paths.latest.golden index 8b919343d21..e83986186c3 100644 --- a/agent/xds/testdata/routes/expose-paths-local-app-paths.latest.golden +++ b/agent/xds/testdata/routes/expose-paths-local-app-paths.latest.golden @@ -1,5 +1,53 @@ { "nonce": "00000001", + "resources": [ + { + "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", + "name": "exposed_path_filter_health1_21500", + "validateClusters": true, + "virtualHosts": [ + { + "domains": [ + "*" + ], + "name": "exposed_path_filter_health1_21500", + "routes": [ + { + "match": { + "path": "/health1" + }, + "route": { + "cluster": "local_app" + } + } + ] + } + ] + }, + { + "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", + "name": "exposed_path_filter_health2_21501", + "validateClusters": true, + "virtualHosts": [ + { + "domains": [ + "*" + ], + "name": "exposed_path_filter_health2_21501", + "routes": [ + { + "match": { + "path": "/health2" + }, + "route": { + "cluster": "local_app" + } + } + ] + } + ] + } + ], "typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", "versionInfo": "00000001" -} \ No newline at end of file +} diff --git a/agent/xds/testdata/routes/expose-paths-new-cluster-http2.latest.golden b/agent/xds/testdata/routes/expose-paths-new-cluster-http2.latest.golden index 8b919343d21..2b38c9521f2 100644 --- a/agent/xds/testdata/routes/expose-paths-new-cluster-http2.latest.golden +++ b/agent/xds/testdata/routes/expose-paths-new-cluster-http2.latest.golden @@ -1,5 +1,53 @@ { "nonce": "00000001", + "resources": [ + { + "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", + "name": "exposed_path_filter_grpchealthv1HealthCheck_21501", + "validateClusters": true, + "virtualHosts": [ + { + "domains": [ + "*" + ], + "name": "exposed_path_filter_grpchealthv1HealthCheck_21501", + "routes": [ + { + "match": { + "path": "/grpc.health.v1.Health/Check" + }, + "route": { + "cluster": "exposed_cluster_9090" + } + } + ] + } + ] + }, + { + "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", + "name": "exposed_path_filter_health1_21500", + "validateClusters": true, + "virtualHosts": [ + { + "domains": [ + "*" + ], + "name": "exposed_path_filter_health1_21500", + "routes": [ + { + "match": { + "path": "/health1" + }, + "route": { + "cluster": "local_app" + } + } + ] + } + ] + } + ], "typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", "versionInfo": "00000001" -} \ No newline at end of file +} From d90f8104c9525f203ad61b7537e41f43c5621cce Mon Sep 17 00:00:00 2001 From: John Murret Date: Mon, 6 Nov 2023 13:23:39 -0700 Subject: [PATCH 2/6] fix failing expose paths tests --- agent/xds/resources_test.go | 16 ++++--- .../endpoints/expose-checks.latest.golden | 22 --------- ...paths-grpc-new-cluster-http1.latest.golden | 22 --------- ...pose-paths-new-cluster-http2.latest.golden | 22 --------- .../routes/expose-checks.latest.golden | 25 ---------- ...paths-grpc-new-cluster-http1.latest.golden | 48 ------------------- ...expose-paths-local-app-paths.latest.golden | 48 ------------------- ...pose-paths-new-cluster-http2.latest.golden | 48 ------------------- 8 files changed, 10 insertions(+), 241 deletions(-) diff --git a/agent/xds/resources_test.go b/agent/xds/resources_test.go index 61d29209279..13a76ca1d71 100644 --- a/agent/xds/resources_test.go +++ b/agent/xds/resources_test.go @@ -1057,7 +1057,8 @@ func getExposePathGoldenTestCases() []goldenTestCase { create: func(t testinf.T) *proxycfg.ConfigSnapshot { return proxycfg.TestConfigSnapshotExposeConfig(t, nil) }, - alsoRunTestForV2: true, + // TODO(jm): enable with https://github.com/hashicorp/consul/pull/19459 + alsoRunTestForV2: false, }, { name: "downstream-service-with-unix-sockets", @@ -1084,7 +1085,8 @@ func getExposePathGoldenTestCases() []goldenTestCase { } }) }, - alsoRunTestForV2: true, + // TODO(jm): enable with https://github.com/hashicorp/consul/pull/19459 + alsoRunTestForV2: false, }, { name: "expose-checks", @@ -1094,12 +1096,14 @@ func getExposePathGoldenTestCases() []goldenTestCase { return "192.0.2.1" }) }, - alsoRunTestForV2: true, + // TODO(jm): enable with https://github.com/hashicorp/consul/pull/19459 + alsoRunTestForV2: false, }, { - name: "expose-paths-grpc-new-cluster-http1", - create: proxycfg.TestConfigSnapshotGRPCExposeHTTP1, - alsoRunTestForV2: true, + name: "expose-paths-grpc-new-cluster-http1", + create: proxycfg.TestConfigSnapshotGRPCExposeHTTP1, + // TODO(jm): enable with https://github.com/hashicorp/consul/pull/19459 + alsoRunTestForV2: false, }, { // NOTE: if IPv6 is not supported in the kernel per diff --git a/agent/xds/testdata/endpoints/expose-checks.latest.golden b/agent/xds/testdata/endpoints/expose-checks.latest.golden index 6efb224f038..a36efb2584a 100644 --- a/agent/xds/testdata/endpoints/expose-checks.latest.golden +++ b/agent/xds/testdata/endpoints/expose-checks.latest.golden @@ -1,27 +1,5 @@ { "nonce": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "exposed_cluster_8181", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8181 - } - } - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "versionInfo": "00000001" } diff --git a/agent/xds/testdata/endpoints/expose-paths-grpc-new-cluster-http1.latest.golden b/agent/xds/testdata/endpoints/expose-paths-grpc-new-cluster-http1.latest.golden index bd0a8f6255e..a36efb2584a 100644 --- a/agent/xds/testdata/endpoints/expose-paths-grpc-new-cluster-http1.latest.golden +++ b/agent/xds/testdata/endpoints/expose-paths-grpc-new-cluster-http1.latest.golden @@ -1,27 +1,5 @@ { "nonce": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "exposed_cluster_8090", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8090 - } - } - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "versionInfo": "00000001" } diff --git a/agent/xds/testdata/endpoints/expose-paths-new-cluster-http2.latest.golden b/agent/xds/testdata/endpoints/expose-paths-new-cluster-http2.latest.golden index 73d2d630f24..a36efb2584a 100644 --- a/agent/xds/testdata/endpoints/expose-paths-new-cluster-http2.latest.golden +++ b/agent/xds/testdata/endpoints/expose-paths-new-cluster-http2.latest.golden @@ -1,27 +1,5 @@ { "nonce": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "exposed_cluster_9090", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 9090 - } - } - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "versionInfo": "00000001" } diff --git a/agent/xds/testdata/routes/expose-checks.latest.golden b/agent/xds/testdata/routes/expose-checks.latest.golden index 2adf5dc233f..df1ae2ff9df 100644 --- a/agent/xds/testdata/routes/expose-checks.latest.golden +++ b/agent/xds/testdata/routes/expose-checks.latest.golden @@ -1,30 +1,5 @@ { "nonce": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", - "name": "exposed_path_filter_debug_21500", - "validateClusters": true, - "virtualHosts": [ - { - "domains": [ - "*" - ], - "name": "exposed_path_filter_debug_21500", - "routes": [ - { - "match": { - "path": "/debug" - }, - "route": { - "cluster": "exposed_cluster_8181" - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", "versionInfo": "00000001" } diff --git a/agent/xds/testdata/routes/expose-paths-grpc-new-cluster-http1.latest.golden b/agent/xds/testdata/routes/expose-paths-grpc-new-cluster-http1.latest.golden index 5787405ef4d..df1ae2ff9df 100644 --- a/agent/xds/testdata/routes/expose-paths-grpc-new-cluster-http1.latest.golden +++ b/agent/xds/testdata/routes/expose-paths-grpc-new-cluster-http1.latest.golden @@ -1,53 +1,5 @@ { "nonce": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", - "name": "exposed_path_filter_healthz_21500", - "validateClusters": true, - "virtualHosts": [ - { - "domains": [ - "*" - ], - "name": "exposed_path_filter_healthz_21500", - "routes": [ - { - "match": { - "path": "/healthz" - }, - "route": { - "cluster": "exposed_cluster_8090" - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", - "name": "public_listener", - "validateClusters": true, - "virtualHosts": [ - { - "domains": [ - "*" - ], - "name": "public_listener", - "routes": [ - { - "match": { - "prefix": "/" - }, - "route": { - "cluster": "local_app" - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", "versionInfo": "00000001" } diff --git a/agent/xds/testdata/routes/expose-paths-local-app-paths.latest.golden b/agent/xds/testdata/routes/expose-paths-local-app-paths.latest.golden index e83986186c3..df1ae2ff9df 100644 --- a/agent/xds/testdata/routes/expose-paths-local-app-paths.latest.golden +++ b/agent/xds/testdata/routes/expose-paths-local-app-paths.latest.golden @@ -1,53 +1,5 @@ { "nonce": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", - "name": "exposed_path_filter_health1_21500", - "validateClusters": true, - "virtualHosts": [ - { - "domains": [ - "*" - ], - "name": "exposed_path_filter_health1_21500", - "routes": [ - { - "match": { - "path": "/health1" - }, - "route": { - "cluster": "local_app" - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", - "name": "exposed_path_filter_health2_21501", - "validateClusters": true, - "virtualHosts": [ - { - "domains": [ - "*" - ], - "name": "exposed_path_filter_health2_21501", - "routes": [ - { - "match": { - "path": "/health2" - }, - "route": { - "cluster": "local_app" - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", "versionInfo": "00000001" } diff --git a/agent/xds/testdata/routes/expose-paths-new-cluster-http2.latest.golden b/agent/xds/testdata/routes/expose-paths-new-cluster-http2.latest.golden index 2b38c9521f2..df1ae2ff9df 100644 --- a/agent/xds/testdata/routes/expose-paths-new-cluster-http2.latest.golden +++ b/agent/xds/testdata/routes/expose-paths-new-cluster-http2.latest.golden @@ -1,53 +1,5 @@ { "nonce": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", - "name": "exposed_path_filter_grpchealthv1HealthCheck_21501", - "validateClusters": true, - "virtualHosts": [ - { - "domains": [ - "*" - ], - "name": "exposed_path_filter_grpchealthv1HealthCheck_21501", - "routes": [ - { - "match": { - "path": "/grpc.health.v1.Health/Check" - }, - "route": { - "cluster": "exposed_cluster_9090" - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", - "name": "exposed_path_filter_health1_21500", - "validateClusters": true, - "virtualHosts": [ - { - "domains": [ - "*" - ], - "name": "exposed_path_filter_health1_21500", - "routes": [ - { - "match": { - "path": "/health1" - }, - "route": { - "cluster": "local_app" - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", "versionInfo": "00000001" } From be3632c5a96254b3c75195fe9a3b7ff894b94e4c Mon Sep 17 00:00:00 2001 From: John Murret Date: Tue, 7 Nov 2023 14:59:16 -0700 Subject: [PATCH 3/6] fix the way endpoint resources get created to make expose tests pass. --- agent/xds/resources_test.go | 18 +++---- agent/xdsv2/cluster_resources.go | 90 +++++++++++++++++++++----------- agent/xdsv2/route_resources.go | 11 ++-- 3 files changed, 70 insertions(+), 49 deletions(-) diff --git a/agent/xds/resources_test.go b/agent/xds/resources_test.go index 13a76ca1d71..6ff5ec9e751 100644 --- a/agent/xds/resources_test.go +++ b/agent/xds/resources_test.go @@ -148,7 +148,7 @@ func TestAllResourcesFromSnapshot(t *testing.T) { if tt.alsoRunTestForV2 { generator := xdsv2.NewResourceGenerator(testutil.Logger(t)) - converter := proxystateconverter.NewConverter(testutil.Logger(t), &mockCfgFetcher{addressLan: "10.10.10.10"}) + converter := proxystateconverter.NewConverter(testutil.Logger(t), &mockCfgFetcher{addressLan: "192.0.2.1"}) proxyState, err := converter.ProxyStateFromSnapshot(snap) require.NoError(t, err) @@ -1057,8 +1057,7 @@ func getExposePathGoldenTestCases() []goldenTestCase { create: func(t testinf.T) *proxycfg.ConfigSnapshot { return proxycfg.TestConfigSnapshotExposeConfig(t, nil) }, - // TODO(jm): enable with https://github.com/hashicorp/consul/pull/19459 - alsoRunTestForV2: false, + alsoRunTestForV2: true, }, { name: "downstream-service-with-unix-sockets", @@ -1085,8 +1084,7 @@ func getExposePathGoldenTestCases() []goldenTestCase { } }) }, - // TODO(jm): enable with https://github.com/hashicorp/consul/pull/19459 - alsoRunTestForV2: false, + alsoRunTestForV2: true, }, { name: "expose-checks", @@ -1096,14 +1094,12 @@ func getExposePathGoldenTestCases() []goldenTestCase { return "192.0.2.1" }) }, - // TODO(jm): enable with https://github.com/hashicorp/consul/pull/19459 - alsoRunTestForV2: false, + alsoRunTestForV2: true, }, { - name: "expose-paths-grpc-new-cluster-http1", - create: proxycfg.TestConfigSnapshotGRPCExposeHTTP1, - // TODO(jm): enable with https://github.com/hashicorp/consul/pull/19459 - alsoRunTestForV2: false, + name: "expose-paths-grpc-new-cluster-http1", + create: proxycfg.TestConfigSnapshotGRPCExposeHTTP1, + alsoRunTestForV2: true, }, { // NOTE: if IPv6 is not supported in the kernel per diff --git a/agent/xdsv2/cluster_resources.go b/agent/xdsv2/cluster_resources.go index 6e33d64ecf6..4ced64f8a8e 100644 --- a/agent/xdsv2/cluster_resources.go +++ b/agent/xdsv2/cluster_resources.go @@ -8,6 +8,7 @@ import ( "fmt" envoy_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3" envoy_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" + envoy_endpoint_v3 "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3" envoy_aggregate_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/clusters/aggregate/v3" envoy_upstreams_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3" envoy_type_v3 "github.com/envoyproxy/go-control-plane/envoy/type/v3" @@ -18,39 +19,47 @@ import ( "github.com/hashicorp/consul/proto-public/pbmesh/v2beta1/pbproxystate" ) -func (pr *ProxyResources) makeClusters(name string) (map[string]proto.Message, error) { +func (pr *ProxyResources) makeClustersAndEndpoints(name string) (map[string]proto.Message, map[string]proto.Message, error) { envoyClusters := make(map[string]proto.Message) + envoyEndpoints := make(map[string]proto.Message) proxyStateCluster, ok := pr.proxyState.Clusters[name] if !ok { - return nil, fmt.Errorf("cluster %q not found", name) + return nil, nil, fmt.Errorf("cluster %q not found", name) } switch proxyStateCluster.Group.(type) { case *pbproxystate.Cluster_FailoverGroup: fg := proxyStateCluster.GetFailoverGroup() - clusters, err := pr.makeEnvoyAggregateCluster(name, proxyStateCluster.Protocol, fg) + clusters, eps, err := pr.makeEnvoyAggregateCluster(name, proxyStateCluster.Protocol, fg) if err != nil { - return nil, err + return nil, nil, err } for _, c := range clusters { envoyClusters[c.Name] = c + if ep, ok := eps[c.Name]; ok { + envoyEndpoints[c.Name] = ep + } } case *pbproxystate.Cluster_EndpointGroup: eg := proxyStateCluster.GetEndpointGroup() - cluster, err := pr.makeEnvoyCluster(name, proxyStateCluster.Protocol, eg) + cluster, eps, err := pr.makeEnvoyCluster(name, proxyStateCluster.Protocol, eg) if err != nil { - return nil, err + return nil, nil, err } envoyClusters[cluster.Name] = cluster + if ep, ok := eps[cluster.Name]; ok { + envoyEndpoints[cluster.Name] = ep + } default: - return nil, errors.New("cluster group type should be Endpoint Group or Failover Group") + return nil, nil, errors.New("cluster group type should be Endpoint Group or Failover Group") } - return envoyClusters, nil + return envoyClusters, envoyEndpoints, nil } -func (pr *ProxyResources) makeEnvoyCluster(name string, protocol pbproxystate.Protocol, eg *pbproxystate.EndpointGroup) (*envoy_cluster_v3.Cluster, error) { +func (pr *ProxyResources) makeEnvoyCluster(name string, protocol pbproxystate.Protocol, + eg *pbproxystate.EndpointGroup) (*envoy_cluster_v3.Cluster, map[string]*envoy_endpoint_v3.ClusterLoadAssignment, error) { if eg != nil { switch t := eg.Group.(type) { case *pbproxystate.EndpointGroup_Dynamic: @@ -66,13 +75,14 @@ func (pr *ProxyResources) makeEnvoyCluster(name string, protocol pbproxystate.Pr passthrough := eg.GetPassthrough() return pr.makeEnvoyPassthroughCluster(name, protocol, passthrough) default: - return nil, fmt.Errorf("unsupported endpoint group type: %s", t) + return nil, nil, fmt.Errorf("unsupported endpoint group type: %s", t) } } - return nil, fmt.Errorf("no endpoint group") + return nil, nil, fmt.Errorf("no endpoint group") } -func (pr *ProxyResources) makeEnvoyDynamicCluster(name string, protocol pbproxystate.Protocol, dynamic *pbproxystate.DynamicEndpointGroup) (*envoy_cluster_v3.Cluster, error) { +func (pr *ProxyResources) makeEnvoyDynamicCluster(name string, protocol pbproxystate.Protocol, + dynamic *pbproxystate.DynamicEndpointGroup) (*envoy_cluster_v3.Cluster, map[string]*envoy_endpoint_v3.ClusterLoadAssignment, error) { cluster := &envoy_cluster_v3.Cluster{ Name: name, ClusterDiscoveryType: &envoy_cluster_v3.Cluster_Type{Type: envoy_cluster_v3.Cluster_EDS}, @@ -87,7 +97,7 @@ func (pr *ProxyResources) makeEnvoyDynamicCluster(name string, protocol pbproxys } err := addHttpProtocolOptions(protocol, cluster) if err != nil { - return nil, err + return nil, nil, err } if dynamic.Config != nil { if dynamic.Config.UseAltStatName { @@ -106,23 +116,32 @@ func (pr *ProxyResources) makeEnvoyDynamicCluster(name string, protocol pbproxys err := addEnvoyLBToCluster(dynamic.Config, cluster) if err != nil { - return nil, err + return nil, nil, err } } if dynamic.OutboundTls != nil { envoyTransportSocket, err := pr.makeEnvoyTransportSocket(dynamic.OutboundTls) if err != nil { - return nil, err + return nil, nil, err } cluster.TransportSocket = envoyTransportSocket } - return cluster, nil + endpointResources := make(map[string]*envoy_endpoint_v3.ClusterLoadAssignment) + if cluster.Name != xdscommon.LocalAppClusterName { + if endpointList, ok := pr.proxyState.Endpoints[cluster.Name]; ok { + protoEndpoint := makeEnvoyClusterLoadAssignment(cluster.Name, endpointList.Endpoints) + endpointResources[cluster.Name] = protoEndpoint + } + } + + return cluster, endpointResources, nil } -func (pr *ProxyResources) makeEnvoyStaticCluster(name string, protocol pbproxystate.Protocol, static *pbproxystate.StaticEndpointGroup) (*envoy_cluster_v3.Cluster, error) { +func (pr *ProxyResources) makeEnvoyStaticCluster(name string, protocol pbproxystate.Protocol, + static *pbproxystate.StaticEndpointGroup) (*envoy_cluster_v3.Cluster, map[string]*envoy_endpoint_v3.ClusterLoadAssignment, error) { cluster := &envoy_cluster_v3.Cluster{ Name: name, ClusterDiscoveryType: &envoy_cluster_v3.Cluster_Type{Type: envoy_cluster_v3.Cluster_STATIC}, @@ -141,21 +160,23 @@ func (pr *ProxyResources) makeEnvoyStaticCluster(name string, protocol pbproxyst err = addHttpProtocolOptions(protocol, cluster) } if err != nil { - return nil, err + return nil, nil, err } if static.Config != nil { cluster.ConnectTimeout = static.Config.ConnectTimeout addEnvoyCircuitBreakers(static.GetConfig().CircuitBreakers, cluster) } - return cluster, nil + return cluster, nil, nil } -func (pr *ProxyResources) makeEnvoyDnsCluster(name string, protocol pbproxystate.Protocol, dns *pbproxystate.DNSEndpointGroup) (*envoy_cluster_v3.Cluster, error) { - return nil, nil +func (pr *ProxyResources) makeEnvoyDnsCluster(name string, protocol pbproxystate.Protocol, + dns *pbproxystate.DNSEndpointGroup) (*envoy_cluster_v3.Cluster, map[string]*envoy_endpoint_v3.ClusterLoadAssignment, error) { + return nil, nil, nil } -func (pr *ProxyResources) makeEnvoyPassthroughCluster(name string, protocol pbproxystate.Protocol, passthrough *pbproxystate.PassthroughEndpointGroup) (*envoy_cluster_v3.Cluster, error) { +func (pr *ProxyResources) makeEnvoyPassthroughCluster(name string, protocol pbproxystate.Protocol, + passthrough *pbproxystate.PassthroughEndpointGroup) (*envoy_cluster_v3.Cluster, map[string]*envoy_endpoint_v3.ClusterLoadAssignment, error) { cluster := &envoy_cluster_v3.Cluster{ Name: name, ConnectTimeout: passthrough.Config.ConnectTimeout, @@ -165,35 +186,42 @@ func (pr *ProxyResources) makeEnvoyPassthroughCluster(name string, protocol pbpr if passthrough.OutboundTls != nil { envoyTransportSocket, err := pr.makeEnvoyTransportSocket(passthrough.OutboundTls) if err != nil { - return nil, err + return nil, nil, err } cluster.TransportSocket = envoyTransportSocket } err := addHttpProtocolOptions(protocol, cluster) if err != nil { - return nil, err + return nil, nil, err } - return cluster, nil + return cluster, nil, nil } -func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol pbproxystate.Protocol, fg *pbproxystate.FailoverGroup) (map[string]*envoy_cluster_v3.Cluster, error) { +func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol pbproxystate.Protocol, + fg *pbproxystate.FailoverGroup) (map[string]*envoy_cluster_v3.Cluster, map[string]*envoy_endpoint_v3.ClusterLoadAssignment, error) { clusters := make(map[string]*envoy_cluster_v3.Cluster) + endpointResources := make(map[string]*envoy_endpoint_v3.ClusterLoadAssignment) if fg != nil { var egNames []string for _, eg := range fg.EndpointGroups { - cluster, err := pr.makeEnvoyCluster(eg.Name, protocol, eg) + cluster, _, err := pr.makeEnvoyCluster(eg.Name, protocol, eg) if err != nil { - return nil, err + return nil, nil, err } egNames = append(egNames, cluster.Name) clusters[cluster.Name] = cluster + + if endpointList, ok := pr.proxyState.Endpoints[cluster.Name]; ok { + protoEndpoint := makeEnvoyClusterLoadAssignment(cluster.Name, endpointList.Endpoints) + endpointResources[cluster.Name] = protoEndpoint + } } aggregateClusterConfig, err := anypb.New(&envoy_aggregate_cluster_v3.ClusterConfig{ Clusters: egNames, }) if err != nil { - return nil, err + return nil, nil, err } c := &envoy_cluster_v3.Cluster{ @@ -212,11 +240,11 @@ func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol pbprox } err = addHttpProtocolOptions(protocol, c) if err != nil { - return nil, err + return nil, nil, err } clusters[c.Name] = c } - return clusters, nil + return clusters, endpointResources, nil } func addLocalAppHttpProtocolOptions(protocol pbproxystate.Protocol, c *envoy_cluster_v3.Cluster) error { diff --git a/agent/xdsv2/route_resources.go b/agent/xdsv2/route_resources.go index d2306fd4363..7392221bcc8 100644 --- a/agent/xdsv2/route_resources.go +++ b/agent/xdsv2/route_resources.go @@ -235,16 +235,13 @@ func makeEnvoyQueryParamFromProxystateQueryMatch(psMatch *pbproxystate.QueryPara } func (pr *ProxyResources) addEnvoyClustersAndEndpointsToEnvoyResources(clusterName string) { - clusters, _ := pr.makeClusters(clusterName) + clusters, endpoints, _ := pr.makeClustersAndEndpoints(clusterName) for name, cluster := range clusters { pr.envoyResources[xdscommon.ClusterType][name] = cluster + } - if name != xdscommon.LocalAppClusterName { - if endpointList, ok := pr.proxyState.Endpoints[name]; ok { - protoEndpoint := makeEnvoyClusterLoadAssignment(name, endpointList.Endpoints) - pr.envoyResources[xdscommon.EndpointType][name] = protoEndpoint - } - } + for name, ep := range endpoints { + pr.envoyResources[xdscommon.EndpointType][name] = ep } } From 05cd49300e851114440779421adb8524f3976112 Mon Sep 17 00:00:00 2001 From: John Murret Date: Tue, 7 Nov 2023 18:13:36 -0700 Subject: [PATCH 4/6] wip --- agent/xdsv2/cluster_resources.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/agent/xdsv2/cluster_resources.go b/agent/xdsv2/cluster_resources.go index 4ced64f8a8e..4ac430e183b 100644 --- a/agent/xdsv2/cluster_resources.go +++ b/agent/xdsv2/cluster_resources.go @@ -204,17 +204,17 @@ func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol pbprox if fg != nil { var egNames []string for _, eg := range fg.EndpointGroups { - cluster, _, err := pr.makeEnvoyCluster(eg.Name, protocol, eg) + cluster, eps, err := pr.makeEnvoyCluster(eg.Name, protocol, eg) if err != nil { - return nil, nil, err + return nil, eps, err } egNames = append(egNames, cluster.Name) clusters[cluster.Name] = cluster - if endpointList, ok := pr.proxyState.Endpoints[cluster.Name]; ok { - protoEndpoint := makeEnvoyClusterLoadAssignment(cluster.Name, endpointList.Endpoints) - endpointResources[cluster.Name] = protoEndpoint - } + //if endpointList, ok := pr.proxyState.Endpoints[cluster.Name]; ok { + // protoEndpoint := makeEnvoyClusterLoadAssignment(cluster.Name, endpointList.Endpoints) + endpointResources[cluster.Name] = eps[cluster.Name] + //} } aggregateClusterConfig, err := anypb.New(&envoy_aggregate_cluster_v3.ClusterConfig{ Clusters: egNames, From f5e28f25e6c5f0cd699a64e6832245550c7eb8d3 Mon Sep 17 00:00:00 2001 From: John Murret Date: Wed, 8 Nov 2023 13:48:31 -0700 Subject: [PATCH 5/6] remove endpoint resources that are already inlined on local_app clusters --- agent/xdsv2/cluster_resources.go | 18 ++-- .../endpoints/source/l7-expose-paths.golden | 62 -------------- .../local-and-inbound-connections.golden | 82 ------------------- ...kload-addresses-with-specific-ports.golden | 82 ------------------- ...le-workload-addresses-without-ports.golden | 82 ------------------- ...kload-addresses-with-specific-ports.golden | 42 ---------- ...le-workload-addresses-without-ports.golden | 42 ---------- ...kload-addresses-with-specific-ports.golden | 42 ---------- ...le-workload-addresses-without-ports.golden | 62 -------------- ...ngle-workload-address-without-ports.golden | 82 ------------------- 10 files changed, 12 insertions(+), 584 deletions(-) diff --git a/agent/xdsv2/cluster_resources.go b/agent/xdsv2/cluster_resources.go index 4ac430e183b..3366cfc7884 100644 --- a/agent/xdsv2/cluster_resources.go +++ b/agent/xdsv2/cluster_resources.go @@ -129,12 +129,12 @@ func (pr *ProxyResources) makeEnvoyDynamicCluster(name string, protocol pbproxys } endpointResources := make(map[string]*envoy_endpoint_v3.ClusterLoadAssignment) - if cluster.Name != xdscommon.LocalAppClusterName { - if endpointList, ok := pr.proxyState.Endpoints[cluster.Name]; ok { - protoEndpoint := makeEnvoyClusterLoadAssignment(cluster.Name, endpointList.Endpoints) - endpointResources[cluster.Name] = protoEndpoint - } + //if cluster.Name != xdscommon.LocalAppClusterName { + if endpointList, ok := pr.proxyState.Endpoints[cluster.Name]; ok { + protoEndpoint := makeEnvoyClusterLoadAssignment(cluster.Name, endpointList.Endpoints) + endpointResources[cluster.Name] = protoEndpoint } + //} return cluster, endpointResources, nil @@ -213,7 +213,9 @@ func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol pbprox //if endpointList, ok := pr.proxyState.Endpoints[cluster.Name]; ok { // protoEndpoint := makeEnvoyClusterLoadAssignment(cluster.Name, endpointList.Endpoints) - endpointResources[cluster.Name] = eps[cluster.Name] + if ep, ok := eps[cluster.Name]; ok { + endpointResources[cluster.Name] = ep + } //} } aggregateClusterConfig, err := anypb.New(&envoy_aggregate_cluster_v3.ClusterConfig{ @@ -243,6 +245,10 @@ func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol pbprox return nil, nil, err } clusters[c.Name] = c + if endpointList, ok := pr.proxyState.Endpoints[c.Name]; ok { + protoEndpoint := makeEnvoyClusterLoadAssignment(c.Name, endpointList.Endpoints) + endpointResources[c.Name] = protoEndpoint + } } return clusters, endpointResources, nil } diff --git a/agent/xdsv2/testdata/endpoints/source/l7-expose-paths.golden b/agent/xdsv2/testdata/endpoints/source/l7-expose-paths.golden index 1ccb234c89d..47b46bca225 100644 --- a/agent/xdsv2/testdata/endpoints/source/l7-expose-paths.golden +++ b/agent/xdsv2/testdata/endpoints/source/l7-expose-paths.golden @@ -1,67 +1,5 @@ { "versionInfo": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "exposed_cluster_9090", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 9090 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "exposed_cluster_9091", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 9091 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:port1", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8080 - } - } - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "nonce": "00000001" } \ No newline at end of file diff --git a/agent/xdsv2/testdata/endpoints/source/local-and-inbound-connections.golden b/agent/xdsv2/testdata/endpoints/source/local-and-inbound-connections.golden index c9e8727f031..47b46bca225 100644 --- a/agent/xdsv2/testdata/endpoints/source/local-and-inbound-connections.golden +++ b/agent/xdsv2/testdata/endpoints/source/local-and-inbound-connections.golden @@ -1,87 +1,5 @@ { "versionInfo": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "exposed_cluster_9090", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 9090 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "exposed_cluster_9091", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 9091 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:port1", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8080 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:port3", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8081 - } - } - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "nonce": "00000001" } \ No newline at end of file diff --git a/agent/xdsv2/testdata/endpoints/source/multiple-workload-addresses-with-specific-ports.golden b/agent/xdsv2/testdata/endpoints/source/multiple-workload-addresses-with-specific-ports.golden index 5fc63eef959..47b46bca225 100644 --- a/agent/xdsv2/testdata/endpoints/source/multiple-workload-addresses-with-specific-ports.golden +++ b/agent/xdsv2/testdata/endpoints/source/multiple-workload-addresses-with-specific-ports.golden @@ -1,87 +1,5 @@ { "versionInfo": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:grpc", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8083 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:http", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8081 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:http2", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8082 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:tcp", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8080 - } - } - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "nonce": "00000001" } \ No newline at end of file diff --git a/agent/xdsv2/testdata/endpoints/source/multiple-workload-addresses-without-ports.golden b/agent/xdsv2/testdata/endpoints/source/multiple-workload-addresses-without-ports.golden index 5fc63eef959..47b46bca225 100644 --- a/agent/xdsv2/testdata/endpoints/source/multiple-workload-addresses-without-ports.golden +++ b/agent/xdsv2/testdata/endpoints/source/multiple-workload-addresses-without-ports.golden @@ -1,87 +1,5 @@ { "versionInfo": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:grpc", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8083 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:http", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8081 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:http2", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8082 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:tcp", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8080 - } - } - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "nonce": "00000001" } \ No newline at end of file diff --git a/agent/xdsv2/testdata/endpoints/source/multiport-l4-multiple-workload-addresses-with-specific-ports.golden b/agent/xdsv2/testdata/endpoints/source/multiport-l4-multiple-workload-addresses-with-specific-ports.golden index 916fbc26cea..47b46bca225 100644 --- a/agent/xdsv2/testdata/endpoints/source/multiport-l4-multiple-workload-addresses-with-specific-ports.golden +++ b/agent/xdsv2/testdata/endpoints/source/multiport-l4-multiple-workload-addresses-with-specific-ports.golden @@ -1,47 +1,5 @@ { "versionInfo": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:admin-port", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8080 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:api-port", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 9090 - } - } - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "nonce": "00000001" } \ No newline at end of file diff --git a/agent/xdsv2/testdata/endpoints/source/multiport-l4-multiple-workload-addresses-without-ports.golden b/agent/xdsv2/testdata/endpoints/source/multiport-l4-multiple-workload-addresses-without-ports.golden index 916fbc26cea..47b46bca225 100644 --- a/agent/xdsv2/testdata/endpoints/source/multiport-l4-multiple-workload-addresses-without-ports.golden +++ b/agent/xdsv2/testdata/endpoints/source/multiport-l4-multiple-workload-addresses-without-ports.golden @@ -1,47 +1,5 @@ { "versionInfo": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:admin-port", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8080 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:api-port", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 9090 - } - } - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "nonce": "00000001" } \ No newline at end of file diff --git a/agent/xdsv2/testdata/endpoints/source/multiport-l7-multiple-workload-addresses-with-specific-ports.golden b/agent/xdsv2/testdata/endpoints/source/multiport-l7-multiple-workload-addresses-with-specific-ports.golden index 916fbc26cea..47b46bca225 100644 --- a/agent/xdsv2/testdata/endpoints/source/multiport-l7-multiple-workload-addresses-with-specific-ports.golden +++ b/agent/xdsv2/testdata/endpoints/source/multiport-l7-multiple-workload-addresses-with-specific-ports.golden @@ -1,47 +1,5 @@ { "versionInfo": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:admin-port", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8080 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:api-port", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 9090 - } - } - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "nonce": "00000001" } \ No newline at end of file diff --git a/agent/xdsv2/testdata/endpoints/source/multiport-l7-multiple-workload-addresses-without-ports.golden b/agent/xdsv2/testdata/endpoints/source/multiport-l7-multiple-workload-addresses-without-ports.golden index e3c67d2c90a..47b46bca225 100644 --- a/agent/xdsv2/testdata/endpoints/source/multiport-l7-multiple-workload-addresses-without-ports.golden +++ b/agent/xdsv2/testdata/endpoints/source/multiport-l7-multiple-workload-addresses-without-ports.golden @@ -1,67 +1,5 @@ { "versionInfo": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:admin-port", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8080 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:api-port", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 9090 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:grpc-port", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 9091 - } - } - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "nonce": "00000001" } \ No newline at end of file diff --git a/agent/xdsv2/testdata/endpoints/source/single-workload-address-without-ports.golden b/agent/xdsv2/testdata/endpoints/source/single-workload-address-without-ports.golden index 5fc63eef959..47b46bca225 100644 --- a/agent/xdsv2/testdata/endpoints/source/single-workload-address-without-ports.golden +++ b/agent/xdsv2/testdata/endpoints/source/single-workload-address-without-ports.golden @@ -1,87 +1,5 @@ { "versionInfo": "00000001", - "resources": [ - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:grpc", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8083 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:http", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8081 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:http2", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8082 - } - } - } - } - ] - } - ] - }, - { - "@type": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", - "clusterName": "local_app:tcp", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socketAddress": { - "address": "127.0.0.1", - "portValue": 8080 - } - } - } - } - ] - } - ] - } - ], "typeUrl": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "nonce": "00000001" } \ No newline at end of file From a38c507bfc10506d31e6999eae9ad1c053cca5da Mon Sep 17 00:00:00 2001 From: John Murret Date: Wed, 8 Nov 2023 14:06:39 -0700 Subject: [PATCH 6/6] renaiming and comments --- agent/xdsv2/cluster_resources.go | 37 ++++++++++++++++++------------- agent/xdsv2/listener_resources.go | 2 +- agent/xdsv2/route_resources.go | 1 + 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/agent/xdsv2/cluster_resources.go b/agent/xdsv2/cluster_resources.go index 3366cfc7884..48f61e9c144 100644 --- a/agent/xdsv2/cluster_resources.go +++ b/agent/xdsv2/cluster_resources.go @@ -30,10 +30,11 @@ func (pr *ProxyResources) makeClustersAndEndpoints(name string) (map[string]prot switch proxyStateCluster.Group.(type) { case *pbproxystate.Cluster_FailoverGroup: fg := proxyStateCluster.GetFailoverGroup() - clusters, eps, err := pr.makeEnvoyAggregateCluster(name, proxyStateCluster.Protocol, fg) + clusters, eps, err := pr.makeEnvoyAggregateClusterAndEndpoint(name, proxyStateCluster.Protocol, fg) if err != nil { return nil, nil, err } + // for each cluster, add it to clusters map and add endpoint to endpoint map for _, c := range clusters { envoyClusters[c.Name] = c if ep, ok := eps[c.Name]; ok { @@ -43,10 +44,12 @@ func (pr *ProxyResources) makeClustersAndEndpoints(name string) (map[string]prot case *pbproxystate.Cluster_EndpointGroup: eg := proxyStateCluster.GetEndpointGroup() - cluster, eps, err := pr.makeEnvoyCluster(name, proxyStateCluster.Protocol, eg) + cluster, eps, err := pr.makeEnvoyClusterAndEndpoint(name, proxyStateCluster.Protocol, eg) if err != nil { return nil, nil, err } + + // for each cluster, add it to clusters map and add endpoint to endpoint map envoyClusters[cluster.Name] = cluster if ep, ok := eps[cluster.Name]; ok { envoyEndpoints[cluster.Name] = ep @@ -58,16 +61,16 @@ func (pr *ProxyResources) makeClustersAndEndpoints(name string) (map[string]prot return envoyClusters, envoyEndpoints, nil } -func (pr *ProxyResources) makeEnvoyCluster(name string, protocol pbproxystate.Protocol, +func (pr *ProxyResources) makeEnvoyClusterAndEndpoint(name string, protocol pbproxystate.Protocol, eg *pbproxystate.EndpointGroup) (*envoy_cluster_v3.Cluster, map[string]*envoy_endpoint_v3.ClusterLoadAssignment, error) { if eg != nil { switch t := eg.Group.(type) { case *pbproxystate.EndpointGroup_Dynamic: dynamic := eg.GetDynamic() - return pr.makeEnvoyDynamicCluster(name, protocol, dynamic) + return pr.makeEnvoyDynamicClusterAndEndpoint(name, protocol, dynamic) case *pbproxystate.EndpointGroup_Static: static := eg.GetStatic() - return pr.makeEnvoyStaticCluster(name, protocol, static) + return pr.makeEnvoyStaticClusterAndEndpoint(name, protocol, static) case *pbproxystate.EndpointGroup_Dns: dns := eg.GetDns() return pr.makeEnvoyDnsCluster(name, protocol, dns) @@ -81,7 +84,7 @@ func (pr *ProxyResources) makeEnvoyCluster(name string, protocol pbproxystate.Pr return nil, nil, fmt.Errorf("no endpoint group") } -func (pr *ProxyResources) makeEnvoyDynamicCluster(name string, protocol pbproxystate.Protocol, +func (pr *ProxyResources) makeEnvoyDynamicClusterAndEndpoint(name string, protocol pbproxystate.Protocol, dynamic *pbproxystate.DynamicEndpointGroup) (*envoy_cluster_v3.Cluster, map[string]*envoy_endpoint_v3.ClusterLoadAssignment, error) { cluster := &envoy_cluster_v3.Cluster{ Name: name, @@ -128,19 +131,18 @@ func (pr *ProxyResources) makeEnvoyDynamicCluster(name string, protocol pbproxys cluster.TransportSocket = envoyTransportSocket } + // Generate Envoy endpoint endpointResources := make(map[string]*envoy_endpoint_v3.ClusterLoadAssignment) - //if cluster.Name != xdscommon.LocalAppClusterName { if endpointList, ok := pr.proxyState.Endpoints[cluster.Name]; ok { protoEndpoint := makeEnvoyClusterLoadAssignment(cluster.Name, endpointList.Endpoints) endpointResources[cluster.Name] = protoEndpoint } - //} return cluster, endpointResources, nil } -func (pr *ProxyResources) makeEnvoyStaticCluster(name string, protocol pbproxystate.Protocol, +func (pr *ProxyResources) makeEnvoyStaticClusterAndEndpoint(name string, protocol pbproxystate.Protocol, static *pbproxystate.StaticEndpointGroup) (*envoy_cluster_v3.Cluster, map[string]*envoy_endpoint_v3.ClusterLoadAssignment, error) { cluster := &envoy_cluster_v3.Cluster{ Name: name, @@ -197,26 +199,26 @@ func (pr *ProxyResources) makeEnvoyPassthroughCluster(name string, protocol pbpr return cluster, nil, nil } -func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol pbproxystate.Protocol, +func (pr *ProxyResources) makeEnvoyAggregateClusterAndEndpoint(name string, protocol pbproxystate.Protocol, fg *pbproxystate.FailoverGroup) (map[string]*envoy_cluster_v3.Cluster, map[string]*envoy_endpoint_v3.ClusterLoadAssignment, error) { clusters := make(map[string]*envoy_cluster_v3.Cluster) endpointResources := make(map[string]*envoy_endpoint_v3.ClusterLoadAssignment) if fg != nil { var egNames []string for _, eg := range fg.EndpointGroups { - cluster, eps, err := pr.makeEnvoyCluster(eg.Name, protocol, eg) + cluster, eps, err := pr.makeEnvoyClusterAndEndpoint(eg.Name, protocol, eg) if err != nil { return nil, eps, err } egNames = append(egNames, cluster.Name) + + // add failover cluster clusters[cluster.Name] = cluster - //if endpointList, ok := pr.proxyState.Endpoints[cluster.Name]; ok { - // protoEndpoint := makeEnvoyClusterLoadAssignment(cluster.Name, endpointList.Endpoints) + // add endpoint for failover cluster if ep, ok := eps[cluster.Name]; ok { endpointResources[cluster.Name] = ep } - //} } aggregateClusterConfig, err := anypb.New(&envoy_aggregate_cluster_v3.ClusterConfig{ Clusters: egNames, @@ -226,6 +228,7 @@ func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol pbprox return nil, nil, err } + // create aggregate cluster c := &envoy_cluster_v3.Cluster{ Name: name, ConnectTimeout: fg.Config.ConnectTimeout, @@ -244,7 +247,11 @@ func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol pbprox if err != nil { return nil, nil, err } + + // add aggregate cluster clusters[c.Name] = c + + // add endpoint for aggregate cluster if endpointList, ok := pr.proxyState.Endpoints[c.Name]; ok { protoEndpoint := makeEnvoyClusterLoadAssignment(c.Name, endpointList.Endpoints) endpointResources[c.Name] = protoEndpoint @@ -379,7 +386,7 @@ func addEnvoyLBToCluster(dynamicConfig *pbproxystate.DynamicEndpointGroupConfig, return nil } -func (pr *ProxyResources) makeEnvoyClusterFromL4Destination(l4 *pbproxystate.L4Destination) error { +func (pr *ProxyResources) makeEnvoyClustersAndEndpointsFromL4Destination(l4 *pbproxystate.L4Destination) error { switch l4.Destination.(type) { case *pbproxystate.L4Destination_Cluster: pr.addEnvoyClustersAndEndpointsToEnvoyResources(l4.GetCluster().GetName()) diff --git a/agent/xdsv2/listener_resources.go b/agent/xdsv2/listener_resources.go index a7f3976ed57..29c0e42af0e 100644 --- a/agent/xdsv2/listener_resources.go +++ b/agent/xdsv2/listener_resources.go @@ -303,7 +303,7 @@ func (pr *ProxyResources) makeEnvoyResourcesForSNIDestination(sni *pbproxystate. } func (pr *ProxyResources) makeEnvoyResourcesForL4Destination(l4 *pbproxystate.Router_L4) ([]*envoy_listener_v3.Filter, error) { - err := pr.makeEnvoyClusterFromL4Destination(l4.L4) + err := pr.makeEnvoyClustersAndEndpointsFromL4Destination(l4.L4) if err != nil { return nil, err } diff --git a/agent/xdsv2/route_resources.go b/agent/xdsv2/route_resources.go index 7392221bcc8..073b89d22ca 100644 --- a/agent/xdsv2/route_resources.go +++ b/agent/xdsv2/route_resources.go @@ -236,6 +236,7 @@ func makeEnvoyQueryParamFromProxystateQueryMatch(psMatch *pbproxystate.QueryPara func (pr *ProxyResources) addEnvoyClustersAndEndpointsToEnvoyResources(clusterName string) { clusters, endpoints, _ := pr.makeClustersAndEndpoints(clusterName) + for name, cluster := range clusters { pr.envoyResources[xdscommon.ClusterType][name] = cluster }