diff --git a/internal/controlplane/xds_cluster_test.go b/internal/controlplane/xds_cluster_test.go index b9c74b7c6..982e6c115 100644 --- a/internal/controlplane/xds_cluster_test.go +++ b/internal/controlplane/xds_cluster_test.go @@ -211,7 +211,7 @@ func Test_buildCluster(t *testing.T) { rootCA := srv.filemgr.FileDataSource(rootCAPath).GetFilename() t.Run("insecure", func(t *testing.T) { endpoints := srv.buildPolicyEndpoints(&config.Policy{ - Destinations: mustParseURLs("http://example.com"), + Destinations: mustParseURLs("http://example.com", "http://1.2.3.4"), }) cluster := newDefaultEnvoyClusterConfig() cluster.DnsLookupFamily = envoy_config_cluster_v3.Cluster_V4_ONLY @@ -240,6 +240,16 @@ func Test_buildCluster(t *testing.T) { } } } + }, { + "endpoint": { + "address": { + "socketAddress": { + "address": "1.2.3.4", + "ipv4Compat": true, + "portValue": 80 + } + } + } }] }] } @@ -340,9 +350,9 @@ func Test_buildCluster(t *testing.T) { } `, cluster) }) - t.Run("ip address", func(t *testing.T) { + t.Run("ip addresses", func(t *testing.T) { endpoints := srv.buildPolicyEndpoints(&config.Policy{ - Destinations: mustParseURLs("http://127.0.0.1"), + Destinations: mustParseURLs("http://127.0.0.1", "http://127.0.0.2"), }) cluster := newDefaultEnvoyClusterConfig() err := buildCluster(cluster, "example", endpoints, true) @@ -369,6 +379,16 @@ func Test_buildCluster(t *testing.T) { } } } + },{ + "endpoint": { + "address": { + "socketAddress": { + "address": "127.0.0.2", + "ipv4Compat": true, + "portValue": 80 + } + } + } }] }] } diff --git a/internal/controlplane/xds_clusters.go b/internal/controlplane/xds_clusters.go index 41c2d0bf1..ec19ee616 100644 --- a/internal/controlplane/xds_clusters.go +++ b/internal/controlplane/xds_clusters.go @@ -292,13 +292,13 @@ func buildCluster( } // for IPs we use a static discovery type, otherwise we use DNS - isIP := false + allIP := true for _, lbe := range lbEndpoints { - if net.ParseIP(urlutil.StripPort(lbe.GetEndpoint().GetAddress().GetSocketAddress().GetAddress())) != nil { - isIP = true + if net.ParseIP(urlutil.StripPort(lbe.GetEndpoint().GetAddress().GetSocketAddress().GetAddress())) == nil { + allIP = false } } - if isIP { + if allIP { cluster.ClusterDiscoveryType = &envoy_config_cluster_v3.Cluster_Type{Type: envoy_config_cluster_v3.Cluster_STATIC} } else { cluster.ClusterDiscoveryType = &envoy_config_cluster_v3.Cluster_Type{Type: envoy_config_cluster_v3.Cluster_STRICT_DNS}