Skip to content

Commit 2ce7ecd

Browse files
authored
cdsbalancer: test cleanup part 3/N (#6564)
1 parent 7afbb9b commit 2ce7ecd

File tree

5 files changed

+680
-1009
lines changed

5 files changed

+680
-1009
lines changed

internal/testutils/xds/e2e/clientresources.go

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
v3endpointpb "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
3434
v3listenerpb "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
3535
v3routepb "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
36+
v3aggregateclusterpb "github.com/envoyproxy/go-control-plane/envoy/extensions/clusters/aggregate/v3"
3637
v3routerpb "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/router/v3"
3738
v3httppb "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
3839
v3tlspb "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
@@ -450,12 +451,37 @@ const (
450451
LoadBalancingPolicyRingHash
451452
)
452453

454+
// ClusterType specifies the type of the Cluster resource.
455+
type ClusterType int
456+
457+
const (
458+
// ClusterTypeEDS specifies a Cluster that uses EDS to resolve endpoints.
459+
ClusterTypeEDS ClusterType = iota
460+
// ClusterTypeLogicalDNS specifies a Cluster that uses DNS to resolve
461+
// endpoints.
462+
ClusterTypeLogicalDNS
463+
// ClusterTypeAggregate specifies a Cluster that is made up of child
464+
// clusters.
465+
ClusterTypeAggregate
466+
)
467+
453468
// ClusterOptions contains options to configure a Cluster resource.
454469
type ClusterOptions struct {
470+
Type ClusterType
455471
// ClusterName is the name of the Cluster resource.
456472
ClusterName string
457-
// ServiceName is the EDS service name of the Cluster.
473+
// ServiceName is the EDS service name of the Cluster. Applicable only when
474+
// cluster type is EDS.
458475
ServiceName string
476+
// ChildNames is the list of child Cluster names. Applicable only when
477+
// cluster type is Aggregate.
478+
ChildNames []string
479+
// DNSHostName is the dns host name of the Cluster. Applicable only when the
480+
// cluster type is DNS.
481+
DNSHostName string
482+
// DNSPort is the port number of the Cluster. Applicable only when the
483+
// cluster type is DNS.
484+
DNSPort uint32
459485
// Policy is the LB policy to be used.
460486
Policy LoadBalancingPolicy
461487
// SecurityLevel determines the security configuration for the Cluster.
@@ -504,17 +530,51 @@ func ClusterResourceWithOptions(opts ClusterOptions) *v3clusterpb.Cluster {
504530
lbPolicy = v3clusterpb.Cluster_RING_HASH
505531
}
506532
cluster := &v3clusterpb.Cluster{
507-
Name: opts.ClusterName,
508-
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
509-
EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
533+
Name: opts.ClusterName,
534+
LbPolicy: lbPolicy,
535+
}
536+
switch opts.Type {
537+
case ClusterTypeEDS:
538+
cluster.ClusterDiscoveryType = &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS}
539+
cluster.EdsClusterConfig = &v3clusterpb.Cluster_EdsClusterConfig{
510540
EdsConfig: &v3corepb.ConfigSource{
511541
ConfigSourceSpecifier: &v3corepb.ConfigSource_Ads{
512542
Ads: &v3corepb.AggregatedConfigSource{},
513543
},
514544
},
515545
ServiceName: opts.ServiceName,
516-
},
517-
LbPolicy: lbPolicy,
546+
}
547+
case ClusterTypeLogicalDNS:
548+
cluster.ClusterDiscoveryType = &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_LOGICAL_DNS}
549+
cluster.LoadAssignment = &v3endpointpb.ClusterLoadAssignment{
550+
Endpoints: []*v3endpointpb.LocalityLbEndpoints{{
551+
LbEndpoints: []*v3endpointpb.LbEndpoint{{
552+
HostIdentifier: &v3endpointpb.LbEndpoint_Endpoint{
553+
Endpoint: &v3endpointpb.Endpoint{
554+
Address: &v3corepb.Address{
555+
Address: &v3corepb.Address_SocketAddress{
556+
SocketAddress: &v3corepb.SocketAddress{
557+
Address: opts.DNSHostName,
558+
PortSpecifier: &v3corepb.SocketAddress_PortValue{
559+
PortValue: opts.DNSPort,
560+
},
561+
},
562+
},
563+
},
564+
},
565+
},
566+
}},
567+
}},
568+
}
569+
case ClusterTypeAggregate:
570+
cluster.ClusterDiscoveryType = &v3clusterpb.Cluster_ClusterType{
571+
ClusterType: &v3clusterpb.Cluster_CustomClusterType{
572+
Name: "envoy.clusters.aggregate",
573+
TypedConfig: testutils.MarshalAny(&v3aggregateclusterpb.ClusterConfig{
574+
Clusters: opts.ChildNames,
575+
}),
576+
},
577+
}
518578
}
519579
if tlsContext != nil {
520580
cluster.TransportSocket = &v3corepb.TransportSocket{

xds/internal/balancer/cdsbalancer/cdsbalancer_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ import (
6161

6262
const (
6363
clusterName = "cluster1"
64+
edsClusterName = clusterName + "-eds"
65+
dnsClusterName = clusterName + "-dns"
6466
serviceName = "service1"
67+
dnsHostName = "dns_host"
68+
dnsPort = uint32(8080)
6569
defaultTestTimeout = 5 * time.Second
6670
defaultTestShortTimeout = 10 * time.Millisecond // For events expected to *not* happen.
6771
)
@@ -218,6 +222,9 @@ func setupWithManagementServer(t *testing.T) (*e2e.ManagementServer, string, *gr
218222
}
219223
return nil
220224
},
225+
// Required for aggregate clusters as all resources cannot be requested
226+
// at once.
227+
AllowResourceSubset: true,
221228
})
222229
t.Cleanup(cleanup)
223230

0 commit comments

Comments
 (0)