16
16
*
17
17
*/
18
18
19
- // Package clients provides implementations of the xDS and LRS clients,
20
- // enabling applications to communicate with xDS management servers and report
21
- // load.
19
+ // Package clients provides implementations of the clients to interact with
20
+ // xDS and LRS servers.
22
21
//
23
- // xDS Client
22
+ // # xDS Client
24
23
//
25
24
// The xDS client allows applications to:
26
25
// - Create client instances with in-memory configurations.
41
40
//
42
41
// NOTICE: This package is EXPERIMENTAL and may be changed or removed
43
42
// in a later release.
44
- //
45
- // See [README](https://github.com/grpc/grpc-go/tree/master/xds/clients/README.md).
46
43
package clients
47
44
48
- import (
49
- "fmt"
50
- "slices"
51
- "strings"
52
-
53
- "google.golang.org/protobuf/proto"
54
- "google.golang.org/protobuf/types/known/structpb"
55
-
56
- v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
57
- )
58
-
59
- // ServerConfig holds settings for connecting to an xDS management server.
60
- type ServerConfig struct {
61
- // ServerURI is the target URI of the xDS management server.
45
+ // ServerIdentifier holds identifying information for connecting to an xDS
46
+ // management or LRS server.
47
+ type ServerIdentifier struct {
48
+ // ServerURI is the target URI of the server.
62
49
ServerURI string
63
50
64
- // IgnoreResourceDeletion is a server feature which if set to true,
65
- // indicates that resource deletion errors can be ignored and cached
66
- // resource data can be used.
67
- //
68
- // This will be removed in the future once we implement gRFC A88
69
- // and two new fields FailOnDataErrors and
70
- // ResourceTimerIsTransientError will be introduced.
71
- IgnoreResourceDeletion bool
72
-
73
51
// Extensions can be populated with arbitrary data to be passed to the
74
- // [ TransportBuilder] and/or xDS Client's ResourceType implementations.
52
+ // TransportBuilder and/or xDS Client's ResourceType implementations.
75
53
// This field can be used to provide additional configuration or context
76
54
// specific to the user's needs.
77
55
//
78
56
// The xDS and LRS clients do not interpret the contents of this field.
79
- // It is the responsibility of the user's custom [ TransportBuilder] and/or
57
+ // It is the responsibility of the user's custom TransportBuilder and/or
80
58
// ResourceType implementations to handle and interpret these extensions.
81
59
//
82
- // For example, a custom [ TransportBuilder] might use this field to
60
+ // For example, a custom TransportBuilder might use this field to
83
61
// configure a specific security credentials.
84
- //
85
- // Note: For custom types used in Extensions, ensure an Equal(any) bool
86
- // method is implemented for equality checks on ServerConfig.
87
62
Extensions any
88
63
}
89
64
90
- // equal returns true if sc and other are considered equal.
91
- func (sc * ServerConfig ) equal (other * ServerConfig ) bool {
92
- switch {
93
- case sc == nil && other == nil :
94
- return true
95
- case (sc != nil ) != (other != nil ):
96
- return false
97
- case sc .ServerURI != other .ServerURI :
98
- return false
99
- case sc .IgnoreResourceDeletion != other .IgnoreResourceDeletion :
100
- return false
101
- }
102
- if sc .Extensions == nil && other .Extensions == nil {
103
- return true
104
- }
105
- if ex , ok := sc .Extensions .(interface { Equal (any ) bool }); ok && ex .Equal (other .Extensions ) {
106
- return true
107
- }
108
- return false
109
- }
110
-
111
- // String returns a string representation of the [ServerConfig].
112
- //
113
- // WARNING: This method is primarily intended for logging and testing
114
- // purposes. The output returned by this method is not guaranteed to be stable
115
- // and may change at any time. Do not rely on it for production use.
116
- func (sc * ServerConfig ) String () string {
117
- return strings .Join ([]string {sc .ServerURI , fmt .Sprintf ("%v" , sc .IgnoreResourceDeletion )}, "-" )
118
- }
119
-
120
- // Authority contains configuration for an xDS control plane authority.
121
- type Authority struct {
122
- // XDSServers contains the list of server configurations for this authority.
123
- XDSServers []ServerConfig
124
-
125
- // Extensions can be populated with arbitrary data to be passed to the xDS
126
- // Client's user specific implementations. This field can be used to
127
- // provide additional configuration or context specific to the user's
128
- // needs.
129
- //
130
- // The xDS and LRS clients do not interpret the contents of this field. It
131
- // is the responsibility of the user's implementations to handle and
132
- // interpret these extensions.
133
- Extensions any
134
- }
135
-
136
- // Node represents the identity of the xDS client, allowing
137
- // management servers to identify the source of xDS requests.
65
+ // Node represents the identity of the xDS client, allowing xDS and LRS servers
66
+ // to identify the source of xDS requests.
138
67
type Node struct {
139
68
// ID is a string identifier of the application.
140
69
ID string
@@ -150,40 +79,6 @@ type Node struct {
150
79
UserAgentName string
151
80
// UserAgentVersion is the user agent version of application.
152
81
UserAgentVersion string
153
- // ClientFeatures is a list of xDS features supported by this client.
154
- // These features are set within the xDS client, but may be overridden only
155
- // for testing purposes.
156
- clientFeatures []string
157
- }
158
-
159
- // toProto converts an instance of [Node] to its protobuf representation.
160
- func (n Node ) toProto () * v3corepb.Node {
161
- return & v3corepb.Node {
162
- Id : n .ID ,
163
- Cluster : n .Cluster ,
164
- Locality : func () * v3corepb.Locality {
165
- if n .Locality .isEmpty () {
166
- return nil
167
- }
168
- return & v3corepb.Locality {
169
- Region : n .Locality .Region ,
170
- Zone : n .Locality .Zone ,
171
- SubZone : n .Locality .SubZone ,
172
- }
173
- }(),
174
- Metadata : func () * structpb.Struct {
175
- if n .Metadata == nil {
176
- return nil
177
- }
178
- if md , ok := n .Metadata .(* structpb.Struct ); ok {
179
- return proto .Clone (md ).(* structpb.Struct )
180
- }
181
- return nil
182
- }(),
183
- UserAgentName : n .UserAgentName ,
184
- UserAgentVersionType : & v3corepb.Node_UserAgentVersion {UserAgentVersion : n .UserAgentVersion },
185
- ClientFeatures : slices .Clone (n .clientFeatures ),
186
- }
187
82
}
188
83
189
84
// Locality represents the location of the xDS client application.
@@ -195,13 +90,3 @@ type Locality struct {
195
90
// SubZone is the further subdivision within a zone.
196
91
SubZone string
197
92
}
198
-
199
- // isEmpty reports whether l is considered empty.
200
- func (l Locality ) isEmpty () bool {
201
- return l .equal (Locality {})
202
- }
203
-
204
- // equal returns true if l and other are considered equal.
205
- func (l Locality ) equal (other Locality ) bool {
206
- return l .Region == other .Region && l .Zone == other .Zone && l .SubZone == other .SubZone
207
- }
0 commit comments