Browse Source

Allow multiple endpoints in Envoy clusters configured with hostnames (#21655)

* xds: allow multiple endpoints for strict_dns

* xds: fixes typo in multi hostname warning
pull/21881/head
Tom Davies 3 weeks ago committed by GitHub
parent
commit
31aae80389
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      .changelog/21655.txt
  2. 13
      agent/xds/clusters.go

3
.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"
```

13
agent/xds/clusters.go

@ -1824,13 +1824,15 @@ func configureClusterWithHostnames(
cluster.DnsRefreshRate = durationpb.New(rate) cluster.DnsRefreshRate = durationpb.New(rate)
cluster.DnsLookupFamily = envoy_cluster_v3.Cluster_V4_ONLY cluster.DnsLookupFamily = envoy_cluster_v3.Cluster_V4_ONLY
envoyMaxEndpoints := 1
discoveryType := envoy_cluster_v3.Cluster_Type{Type: envoy_cluster_v3.Cluster_LOGICAL_DNS} discoveryType := envoy_cluster_v3.Cluster_Type{Type: envoy_cluster_v3.Cluster_LOGICAL_DNS}
if dnsDiscoveryType == "strict_dns" { if dnsDiscoveryType == "strict_dns" {
discoveryType.Type = envoy_cluster_v3.Cluster_STRICT_DNS discoveryType.Type = envoy_cluster_v3.Cluster_STRICT_DNS
envoyMaxEndpoints = len(hostnameEndpoints)
} }
cluster.ClusterDiscoveryType = &discoveryType cluster.ClusterDiscoveryType = &discoveryType
endpoints := make([]*envoy_endpoint_v3.LbEndpoint, 0, 1) endpoints := make([]*envoy_endpoint_v3.LbEndpoint, 0, envoyMaxEndpoints)
uniqueHostnames := make(map[string]bool) uniqueHostnames := make(map[string]bool)
var ( var (
@ -1848,14 +1850,17 @@ func configureClusterWithHostnames(
continue continue
} }
if len(endpoints) == 0 { if len(endpoints) < envoyMaxEndpoints {
endpoints = append(endpoints, makeLbEndpoint(addr, port, health, weight)) endpoints = append(endpoints, makeLbEndpoint(addr, port, health, weight))
hostname = addr hostname = addr
idx = i idx = i
if len(endpoints) == envoyMaxEndpoints {
break break
} }
} }
}
dc := hostnameEndpoints[idx].Node.Datacenter dc := hostnameEndpoints[idx].Node.Datacenter
service := hostnameEndpoints[idx].Service.CompoundServiceName() service := hostnameEndpoints[idx].Service.CompoundServiceName()
@ -1867,8 +1872,8 @@ func configureClusterWithHostnames(
endpoints = append(endpoints, fallback) 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), 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()) "dc", dc, "service", service.String())
} }

Loading…
Cancel
Save