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

cdsbalancer: test cleanup part 3/N #6564

Merged
merged 6 commits into from
Aug 25, 2023
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
72 changes: 66 additions & 6 deletions internal/testutils/xds/e2e/clientresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
v3endpointpb "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
v3listenerpb "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
v3routepb "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
v3aggregateclusterpb "github.com/envoyproxy/go-control-plane/envoy/extensions/clusters/aggregate/v3"
v3routerpb "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/router/v3"
v3httppb "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
v3tlspb "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
Expand Down Expand Up @@ -450,12 +451,37 @@ const (
LoadBalancingPolicyRingHash
)

// ClusterType specifies the type of the Cluster resource.
type ClusterType int

const (
// ClusterTypeEDS specifies a Cluster that uses EDS to resolve endpoints.
ClusterTypeEDS ClusterType = iota
// ClusterTypeLogicalDNS specifies a Cluster that uses DNS to resolve
// endpoints.
ClusterTypeLogicalDNS
// ClusterTypeAggregate specifies a Cluster that is made up of child
// clusters.
ClusterTypeAggregate
)

// ClusterOptions contains options to configure a Cluster resource.
type ClusterOptions struct {
Type ClusterType
// ClusterName is the name of the Cluster resource.
ClusterName string
// ServiceName is the EDS service name of the Cluster.
// ServiceName is the EDS service name of the Cluster. Applicable only when
// cluster type is EDS.
ServiceName string
// ChildNames is the list of child Cluster names. Applicable only when
// cluster type is Aggregate.
ChildNames []string
// DNSHostName is the dns host name of the Cluster. Applicable only when the
// cluster type is DNS.
DNSHostName string
// DNSPort is the port number of the Cluster. Applicable only when the
// cluster type is DNS.
DNSPort uint32
// Policy is the LB policy to be used.
Policy LoadBalancingPolicy
// SecurityLevel determines the security configuration for the Cluster.
Expand Down Expand Up @@ -504,17 +530,51 @@ func ClusterResourceWithOptions(opts ClusterOptions) *v3clusterpb.Cluster {
lbPolicy = v3clusterpb.Cluster_RING_HASH
}
cluster := &v3clusterpb.Cluster{
Name: opts.ClusterName,
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
Name: opts.ClusterName,
LbPolicy: lbPolicy,
}
switch opts.Type {
case ClusterTypeEDS:
cluster.ClusterDiscoveryType = &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS}
cluster.EdsClusterConfig = &v3clusterpb.Cluster_EdsClusterConfig{
EdsConfig: &v3corepb.ConfigSource{
ConfigSourceSpecifier: &v3corepb.ConfigSource_Ads{
Ads: &v3corepb.AggregatedConfigSource{},
},
},
ServiceName: opts.ServiceName,
},
LbPolicy: lbPolicy,
}
case ClusterTypeLogicalDNS:
cluster.ClusterDiscoveryType = &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_LOGICAL_DNS}
cluster.LoadAssignment = &v3endpointpb.ClusterLoadAssignment{
Endpoints: []*v3endpointpb.LocalityLbEndpoints{{
LbEndpoints: []*v3endpointpb.LbEndpoint{{
HostIdentifier: &v3endpointpb.LbEndpoint_Endpoint{
Endpoint: &v3endpointpb.Endpoint{
Address: &v3corepb.Address{
Address: &v3corepb.Address_SocketAddress{
SocketAddress: &v3corepb.SocketAddress{
Address: opts.DNSHostName,
PortSpecifier: &v3corepb.SocketAddress_PortValue{
PortValue: opts.DNSPort,
},
},
},
},
},
},
}},
}},
}
case ClusterTypeAggregate:
cluster.ClusterDiscoveryType = &v3clusterpb.Cluster_ClusterType{
ClusterType: &v3clusterpb.Cluster_CustomClusterType{
Name: "envoy.clusters.aggregate",
TypedConfig: testutils.MarshalAny(&v3aggregateclusterpb.ClusterConfig{
Clusters: opts.ChildNames,
}),
},
}
}
if tlsContext != nil {
cluster.TransportSocket = &v3corepb.TransportSocket{
Expand Down
7 changes: 7 additions & 0 deletions xds/internal/balancer/cdsbalancer/cdsbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ import (

const (
clusterName = "cluster1"
edsClusterName = clusterName + "-eds"
dnsClusterName = clusterName + "-dns"
serviceName = "service1"
dnsHostName = "dns_host"
dnsPort = uint32(8080)
defaultTestTimeout = 5 * time.Second
defaultTestShortTimeout = 10 * time.Millisecond // For events expected to *not* happen.
)
Expand Down Expand Up @@ -218,6 +222,9 @@ func setupWithManagementServer(t *testing.T) (*e2e.ManagementServer, string, *gr
}
return nil
},
// Required for aggregate clusters as all resources cannot be requested
// at once.
AllowResourceSubset: true,
})
t.Cleanup(cleanup)

Expand Down
Loading