Skip to content

Commit bcaf6d8

Browse files
purnesh42Hjanardhankrishna-sai
authored andcommitted
xds: introduce generic xds clients xDS and LRS Client API signatures (grpc#8042)
1 parent 282576c commit bcaf6d8

14 files changed

+801
-525
lines changed

xds/internal/clients/config.go

+12-127
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
*
1717
*/
1818

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.
2221
//
23-
// xDS Client
22+
// # xDS Client
2423
//
2524
// The xDS client allows applications to:
2625
// - Create client instances with in-memory configurations.
@@ -41,100 +40,30 @@
4140
//
4241
// NOTICE: This package is EXPERIMENTAL and may be changed or removed
4342
// in a later release.
44-
//
45-
// See [README](https://github.com/grpc/grpc-go/tree/master/xds/clients/README.md).
4643
package clients
4744

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.
6249
ServerURI string
6350

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-
7351
// 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.
7553
// This field can be used to provide additional configuration or context
7654
// specific to the user's needs.
7755
//
7856
// 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
8058
// ResourceType implementations to handle and interpret these extensions.
8159
//
82-
// For example, a custom [TransportBuilder] might use this field to
60+
// For example, a custom TransportBuilder might use this field to
8361
// 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.
8762
Extensions any
8863
}
8964

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.
13867
type Node struct {
13968
// ID is a string identifier of the application.
14069
ID string
@@ -150,40 +79,6 @@ type Node struct {
15079
UserAgentName string
15180
// UserAgentVersion is the user agent version of application.
15281
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-
}
18782
}
18883

18984
// Locality represents the location of the xDS client application.
@@ -195,13 +90,3 @@ type Locality struct {
19590
// SubZone is the further subdivision within a zone.
19691
SubZone string
19792
}
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

Comments
 (0)