From 31aae80389fa954e35c02f34d97c853f54c8c1b7 Mon Sep 17 00:00:00 2001 From: Tom Davies Date: Mon, 28 Oct 2024 19:18:04 +0000 Subject: [PATCH] Allow multiple endpoints in Envoy clusters configured with hostnames (#21655) * xds: allow multiple endpoints for strict_dns * xds: fixes typo in multi hostname warning --- .changelog/21655.txt | 3 +++ agent/xds/clusters.go | 15 ++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changelog/21655.txt diff --git a/.changelog/21655.txt b/.changelog/21655.txt new file mode 100644 index 0000000000..3ef13bdf88 --- /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 1d69f804c7..244585dfdf 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,8 +1872,8 @@ func configureClusterWithHostnames( endpoints = append(endpoints, fallback) } - if len(uniqueHostnames) > 1 { - logger.Warn(fmt.Sprintf("service contains instances with more than one unique hostname; only %q be resolved by Envoy", hostname), + if len(uniqueHostnames) > 1 && envoyMaxEndpoints == 1 { + 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()) }