@@ -33,6 +33,7 @@ import (
33
33
v3endpointpb "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
34
34
v3listenerpb "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
35
35
v3routepb "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
36
+ v3aggregateclusterpb "github.com/envoyproxy/go-control-plane/envoy/extensions/clusters/aggregate/v3"
36
37
v3routerpb "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/router/v3"
37
38
v3httppb "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
38
39
v3tlspb "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
@@ -450,12 +451,37 @@ const (
450
451
LoadBalancingPolicyRingHash
451
452
)
452
453
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
+
453
468
// ClusterOptions contains options to configure a Cluster resource.
454
469
type ClusterOptions struct {
470
+ Type ClusterType
455
471
// ClusterName is the name of the Cluster resource.
456
472
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.
458
475
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
459
485
// Policy is the LB policy to be used.
460
486
Policy LoadBalancingPolicy
461
487
// SecurityLevel determines the security configuration for the Cluster.
@@ -504,17 +530,51 @@ func ClusterResourceWithOptions(opts ClusterOptions) *v3clusterpb.Cluster {
504
530
lbPolicy = v3clusterpb .Cluster_RING_HASH
505
531
}
506
532
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 {
510
540
EdsConfig : & v3corepb.ConfigSource {
511
541
ConfigSourceSpecifier : & v3corepb.ConfigSource_Ads {
512
542
Ads : & v3corepb.AggregatedConfigSource {},
513
543
},
514
544
},
515
545
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
+ }
518
578
}
519
579
if tlsContext != nil {
520
580
cluster .TransportSocket = & v3corepb.TransportSocket {
0 commit comments