1/*
2 *
3 * Copyright 2021 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package xdsresource
19
20import "google.golang.org/protobuf/types/known/anypb"
21
22// ClusterType is the type of cluster from a received CDS response.
23type ClusterType int
24
25const (
26	// ClusterTypeEDS represents the EDS cluster type, which will delegate endpoint
27	// discovery to the management server.
28	ClusterTypeEDS ClusterType = iota
29	// ClusterTypeLogicalDNS represents the Logical DNS cluster type, which essentially
30	// maps to the gRPC behavior of using the DNS resolver with pick_first LB policy.
31	ClusterTypeLogicalDNS
32	// ClusterTypeAggregate represents the Aggregate Cluster type, which provides a
33	// prioritized list of clusters to use. It is used for failover between clusters
34	// with a different configuration.
35	ClusterTypeAggregate
36)
37
38// ClusterLBPolicyRingHash represents ring_hash lb policy, and also contains its
39// config.
40type ClusterLBPolicyRingHash struct {
41	MinimumRingSize uint64
42	MaximumRingSize uint64
43}
44
45// ClusterUpdate contains information from a received CDS response, which is of
46// interest to the registered CDS watcher.
47type ClusterUpdate struct {
48	ClusterType ClusterType
49	// ClusterName is the clusterName being watched for through CDS.
50	ClusterName string
51	// EDSServiceName is an optional name for EDS. If it's not set, the balancer
52	// should watch ClusterName for the EDS resources.
53	EDSServiceName string
54	// EnableLRS indicates whether or not load should be reported through LRS.
55	EnableLRS bool
56	// SecurityCfg contains security configuration sent by the control plane.
57	SecurityCfg *SecurityConfig
58	// MaxRequests for circuit breaking, if any (otherwise nil).
59	MaxRequests *uint32
60	// DNSHostName is used only for cluster type DNS. It's the DNS name to
61	// resolve in "host:port" form
62	DNSHostName string
63	// PrioritizedClusterNames is used only for cluster type aggregate. It represents
64	// a prioritized list of cluster names.
65	PrioritizedClusterNames []string
66
67	// LBPolicy is the lb policy for this cluster.
68	//
69	// This only support round_robin and ring_hash.
70	// - if it's nil, the lb policy is round_robin
71	// - if it's not nil, the lb policy is ring_hash, the this field has the config.
72	//
73	// When we add more support policies, this can be made an interface, and
74	// will be set to different types based on the policy type.
75	LBPolicy *ClusterLBPolicyRingHash
76
77	// Raw is the resource from the xds response.
78	Raw *anypb.Any
79}
80
81// ClusterUpdateErrTuple is a tuple with the update and error. It contains the
82// results from unmarshal functions. It's used to pass unmarshal results of
83// multiple resources together, e.g. in maps like `map[string]{Update,error}`.
84type ClusterUpdateErrTuple struct {
85	Update ClusterUpdate
86	Err    error
87}
88