in grpc-xds/control-plane-go/pkg/xds/cds/cluster.go [66:124]
func CreateCluster(name string, edsServiceName string, namespace string, serviceAccountName string, healthCheckPort uint32, healthCheckProtocol string, healthCheckPathOrGRPCService string, enableTLS bool, requireClientCerts bool) (*clusterv3.Cluster, error) {
anyWrappedHTTPProtocolOptions, err := anypb.New(&httpv3.HttpProtocolOptions{
UpstreamProtocolOptions: &httpv3.HttpProtocolOptions_ExplicitHttpConfig_{
ExplicitHttpConfig: &httpv3.HttpProtocolOptions_ExplicitHttpConfig{
ProtocolConfig: &httpv3.HttpProtocolOptions_ExplicitHttpConfig_Http2ProtocolOptions{
Http2ProtocolOptions: &corev3.Http2ProtocolOptions{},
},
},
},
})
if err != nil {
return nil, fmt.Errorf("could not marshall HttpProtocolOptions into Any instance: %w", err)
}
cluster := clusterv3.Cluster{
Name: name,
ClusterDiscoveryType: &clusterv3.Cluster_Type{
Type: clusterv3.Cluster_EDS,
},
EdsClusterConfig: &clusterv3.Cluster_EdsClusterConfig{
EdsConfig: &corev3.ConfigSource{
ResourceApiVersion: corev3.ApiVersion_V3,
ConfigSourceSpecifier: &corev3.ConfigSource_Ads{
Ads: &corev3.AggregatedConfigSource{},
},
},
ServiceName: edsServiceName,
},
ConnectTimeout: &durationpb.Duration{
Seconds: 3, // default is 5s
},
// See https://github.com/envoyproxy/envoy/issues/11527
// IgnoreHealthOnHostRemoval: true,
TypedExtensionProtocolOptions: map[string]*anypb.Any{
envoyExtensionsUpstreamsHTTPProtocolOptions: anyWrappedHTTPProtocolOptions,
},
// See https://github.com/envoyproxy/envoy/issues/11527
IgnoreHealthOnHostRemoval: true,
LbPolicy: clusterv3.Cluster_ROUND_ROBIN,
}
// Client-side active health checks. Implemented by Envoy, but not by gRPC clients.
if healthCheckProtocol != "" {
cluster.HealthChecks = []*corev3.HealthCheck{createHealthCheck(healthCheckProtocol, healthCheckPort, healthCheckPathOrGRPCService)}
if healthCheckPort != 0 {
cluster.HealthChecks[0].AltPort = wrapperspb.UInt32(healthCheckPort)
}
}
if enableTLS {
upstreamTLSContext := tls.CreateUpstreamTLSContext(namespace, serviceAccountName, requireClientCerts)
transportSocket, err := tls.CreateTransportSocket(upstreamTLSContext)
if err != nil {
return nil, err
}
cluster.TransportSocket = transportSocket
}
return &cluster, nil
}