From e3f63958181a53b73f0a7ef5ef07c13495566283 Mon Sep 17 00:00:00 2001 From: Tom Davies Date: Sat, 24 Aug 2024 22:34:50 +0000 Subject: [PATCH 1/2] backport of commit a80ee727dd3b0dc4375a1686aa724c763211c0a5 --- .changelog/21655.txt | 3 +++ agent/xds/clusters.go | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 .changelog/21655.txt diff --git a/.changelog/21655.txt b/.changelog/21655.txt new file mode 100644 index 000000000000..3ef13bdf88fa --- /dev/null +++ b/.changelog/21655.txt @@ -0,0 +1,3 @@ +```release-note:improvement +xds: configures Envoy to load balance over all instances of an external service configured with hostnames when "envoy_dns_discovery_type" is set to "STRICT_DNS" +``` diff --git a/agent/xds/clusters.go b/agent/xds/clusters.go index 1d69f804c7dd..4efd0b76749a 100644 --- a/agent/xds/clusters.go +++ b/agent/xds/clusters.go @@ -1824,13 +1824,15 @@ func configureClusterWithHostnames( cluster.DnsRefreshRate = durationpb.New(rate) cluster.DnsLookupFamily = envoy_cluster_v3.Cluster_V4_ONLY + envoyMaxEndpoints := 1 discoveryType := envoy_cluster_v3.Cluster_Type{Type: envoy_cluster_v3.Cluster_LOGICAL_DNS} if dnsDiscoveryType == "strict_dns" { discoveryType.Type = envoy_cluster_v3.Cluster_STRICT_DNS + envoyMaxEndpoints = len(hostnameEndpoints) } cluster.ClusterDiscoveryType = &discoveryType - endpoints := make([]*envoy_endpoint_v3.LbEndpoint, 0, 1) + endpoints := make([]*envoy_endpoint_v3.LbEndpoint, 0, envoyMaxEndpoints) uniqueHostnames := make(map[string]bool) var ( @@ -1848,12 +1850,15 @@ func configureClusterWithHostnames( continue } - if len(endpoints) == 0 { + if len(endpoints) < envoyMaxEndpoints { endpoints = append(endpoints, makeLbEndpoint(addr, port, health, weight)) hostname = addr idx = i - break + + if len(endpoints) == envoyMaxEndpoints { + break + } } } @@ -1867,7 +1872,7 @@ func configureClusterWithHostnames( endpoints = append(endpoints, fallback) } - if len(uniqueHostnames) > 1 { + if len(uniqueHostnames) > 1 && envoyMaxEndpoints == 1 { logger.Warn(fmt.Sprintf("service contains instances with more than one unique hostname; only %q be resolved by Envoy", hostname), "dc", dc, "service", service.String()) } From da515c9514157c70b2463d66f7c09adaaacd47c4 Mon Sep 17 00:00:00 2001 From: Tom Davies Date: Sat, 24 Aug 2024 23:33:00 +0000 Subject: [PATCH 2/2] backport of commit f270ab59465f9ab2f1794f0849ca18bca9f12b93 --- agent/xds/clusters.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/xds/clusters.go b/agent/xds/clusters.go index 4efd0b76749a..244585dfdf3e 100644 --- a/agent/xds/clusters.go +++ b/agent/xds/clusters.go @@ -1873,7 +1873,7 @@ func configureClusterWithHostnames( endpoints = append(endpoints, fallback) } if len(uniqueHostnames) > 1 && envoyMaxEndpoints == 1 { - logger.Warn(fmt.Sprintf("service contains instances with more than one unique hostname; only %q be resolved by Envoy", hostname), + logger.Warn(fmt.Sprintf("service contains instances with more than one unique hostname; only %q will be resolved by Envoy", hostname), "dc", dc, "service", service.String()) }