From fcc18c16755d00926b750b72470bceb1dd54a57f Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Mon, 29 Jul 2019 11:15:55 -0400 Subject: [PATCH] Fix prepared query upstream endpoint generation (#6236) Use the correct SNI value for prepared query upstreams --- agent/proxycfg/testing.go | 3 +- agent/xds/endpoints.go | 2 +- agent/xds/server_test.go | 34 ++++++++++++++++++++ agent/xds/testdata/endpoints/defaults.golden | 34 ++++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) diff --git a/agent/proxycfg/testing.go b/agent/proxycfg/testing.go index b15e59c191..acebcaa685 100644 --- a/agent/proxycfg/testing.go +++ b/agent/proxycfg/testing.go @@ -420,7 +420,8 @@ func TestConfigSnapshot(t testing.T) *ConfigSnapshot { ConnectProxy: configSnapshotConnectProxy{ Leaf: leaf, UpstreamEndpoints: map[string]structs.CheckServiceNodes{ - "db": TestUpstreamNodes(t), + "db": TestUpstreamNodes(t), + "prepared_query:geo-cache": TestUpstreamNodes(t), }, }, Datacenter: "dc1", diff --git a/agent/xds/endpoints.go b/agent/xds/endpoints.go index db946bef19..152b1a711c 100644 --- a/agent/xds/endpoints.go +++ b/agent/xds/endpoints.go @@ -51,7 +51,7 @@ func (s *Server) endpointsFromSnapshotConnectProxy(cfgSnap *proxycfg.ConfigSnaps if chain == nil { // We ONLY want this branch for prepared queries. - sni := ServiceSNI(u.DestinationName, "", u.DestinationNamespace, u.Datacenter, cfgSnap) + sni := UpstreamSNI(&u, "", cfgSnap) endpoints, ok := cfgSnap.ConnectProxy.UpstreamEndpoints[id] if ok { la := makeLoadAssignment( diff --git a/agent/xds/server_test.go b/agent/xds/server_test.go index b651e8cb11..06b96b821b 100644 --- a/agent/xds/server_test.go +++ b/agent/xds/server_test.go @@ -267,6 +267,40 @@ func expectEndpointsJSON(t *testing.T, snap *proxycfg.ConfigSnapshot, token stri ] } ] + }, + { + "@type": "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment", + "clusterName": "geo-cache.default.dc1.query.11111111-2222-3333-4444-555555555555.consul", + "endpoints": [ + { + "lbEndpoints": [ + { + "endpoint": { + "address": { + "socketAddress": { + "address": "10.10.1.1", + "portValue": 8080 + } + } + }, + "healthStatus": "HEALTHY", + "loadBalancingWeight": 1 + }, + { + "endpoint": { + "address": { + "socketAddress": { + "address": "10.10.1.2", + "portValue": 8080 + } + } + }, + "healthStatus": "HEALTHY", + "loadBalancingWeight": 1 + } + ] + } + ] } ], "typeUrl": "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment", diff --git a/agent/xds/testdata/endpoints/defaults.golden b/agent/xds/testdata/endpoints/defaults.golden index 2acef4c0aa..f1c772e1e5 100644 --- a/agent/xds/testdata/endpoints/defaults.golden +++ b/agent/xds/testdata/endpoints/defaults.golden @@ -34,6 +34,40 @@ ] } ] + }, + { + "@type": "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment", + "clusterName": "geo-cache.default.dc1.query.11111111-2222-3333-4444-555555555555.consul", + "endpoints": [ + { + "lbEndpoints": [ + { + "endpoint": { + "address": { + "socketAddress": { + "address": "10.10.1.1", + "portValue": 8080 + } + } + }, + "healthStatus": "HEALTHY", + "loadBalancingWeight": 1 + }, + { + "endpoint": { + "address": { + "socketAddress": { + "address": "10.10.1.2", + "portValue": 8080 + } + } + }, + "healthStatus": "HEALTHY", + "loadBalancingWeight": 1 + } + ] + } + ] } ], "typeUrl": "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment",