Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple endpoints in Envoy clusters configured with hostnames #21655

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/21655.txt
Original file line number Diff line number Diff line change
@@ -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"
```
15 changes: 10 additions & 5 deletions agent/xds/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Copy link
Contributor Author

@t-davies t-davies Aug 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure we do still need to break early here to maintain the same behaviour that we had before with regards to how fallbacks are determined, but happy to be corrected so we can remove this slightly clunky check.

}
}
}

Expand All @@ -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())
}

Expand Down
Loading