Skip to content

Commit 31aae80

Browse files
authored
Allow multiple endpoints in Envoy clusters configured with hostnames (#21655)
* xds: allow multiple endpoints for strict_dns * xds: fixes typo in multi hostname warning
1 parent 40c7f73 commit 31aae80

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

.changelog/21655.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:improvement
2+
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"
3+
```

agent/xds/clusters.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,13 +1824,15 @@ func configureClusterWithHostnames(
18241824
cluster.DnsRefreshRate = durationpb.New(rate)
18251825
cluster.DnsLookupFamily = envoy_cluster_v3.Cluster_V4_ONLY
18261826

1827+
envoyMaxEndpoints := 1
18271828
discoveryType := envoy_cluster_v3.Cluster_Type{Type: envoy_cluster_v3.Cluster_LOGICAL_DNS}
18281829
if dnsDiscoveryType == "strict_dns" {
18291830
discoveryType.Type = envoy_cluster_v3.Cluster_STRICT_DNS
1831+
envoyMaxEndpoints = len(hostnameEndpoints)
18301832
}
18311833
cluster.ClusterDiscoveryType = &discoveryType
18321834

1833-
endpoints := make([]*envoy_endpoint_v3.LbEndpoint, 0, 1)
1835+
endpoints := make([]*envoy_endpoint_v3.LbEndpoint, 0, envoyMaxEndpoints)
18341836
uniqueHostnames := make(map[string]bool)
18351837

18361838
var (
@@ -1848,12 +1850,15 @@ func configureClusterWithHostnames(
18481850
continue
18491851
}
18501852

1851-
if len(endpoints) == 0 {
1853+
if len(endpoints) < envoyMaxEndpoints {
18521854
endpoints = append(endpoints, makeLbEndpoint(addr, port, health, weight))
18531855

18541856
hostname = addr
18551857
idx = i
1856-
break
1858+
1859+
if len(endpoints) == envoyMaxEndpoints {
1860+
break
1861+
}
18571862
}
18581863
}
18591864

@@ -1867,8 +1872,8 @@ func configureClusterWithHostnames(
18671872

18681873
endpoints = append(endpoints, fallback)
18691874
}
1870-
if len(uniqueHostnames) > 1 {
1871-
logger.Warn(fmt.Sprintf("service contains instances with more than one unique hostname; only %q be resolved by Envoy", hostname),
1875+
if len(uniqueHostnames) > 1 && envoyMaxEndpoints == 1 {
1876+
logger.Warn(fmt.Sprintf("service contains instances with more than one unique hostname; only %q will be resolved by Envoy", hostname),
18721877
"dc", dc, "service", service.String())
18731878
}
18741879

0 commit comments

Comments
 (0)