Skip to content

Commit 4e9b596

Browse files
authored
xds: add support for multiple xDS clients, for fallback (#7347)
1 parent 5ac73ac commit 4e9b596

37 files changed

Lines changed: 1365 additions & 759 deletions

internal/testutils/xds/e2e/logging.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ type serverLogger struct {
2727
}
2828

2929
func (l serverLogger) Debugf(format string, args ...any) {
30-
l.logger.Logf(format, args)
30+
l.logger.Logf(format, args...)
3131
}
3232
func (l serverLogger) Infof(format string, args ...any) {
33-
l.logger.Logf(format, args)
33+
l.logger.Logf(format, args...)
3434
}
3535
func (l serverLogger) Warnf(format string, args ...any) {
36-
l.logger.Logf(format, args)
36+
l.logger.Logf(format, args...)
3737
}
3838
func (l serverLogger) Errorf(format string, args ...any) {
39-
l.logger.Logf(format, args)
39+
l.logger.Logf(format, args...)
4040
}

internal/xds/bootstrap/bootstrap.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"google.golang.org/grpc/credentials/tls/certprovider"
3535
"google.golang.org/grpc/internal"
3636
"google.golang.org/grpc/internal/envconfig"
37-
"google.golang.org/grpc/internal/pretty"
3837
"google.golang.org/grpc/xds/bootstrap"
3938
"google.golang.org/protobuf/proto"
4039
"google.golang.org/protobuf/types/known/structpb"
@@ -213,6 +212,9 @@ func (sc *ServerConfig) Equal(other *ServerConfig) bool {
213212
// content. It doesn't cover NodeProto because NodeProto isn't used by
214213
// federation.
215214
func (sc *ServerConfig) String() string {
215+
if len(sc.serverFeatures) == 0 {
216+
return fmt.Sprintf("%s-%s", sc.serverURI, sc.selectedCreds.String())
217+
}
216218
features := strings.Join(sc.serverFeatures, "-")
217219
return strings.Join([]string{sc.serverURI, sc.selectedCreds.String(), features}, "-")
218220
}
@@ -418,6 +420,12 @@ func (c *Config) Equal(other *Config) bool {
418420
return true
419421
}
420422

423+
// String returns a string representation of the Config.
424+
func (c *Config) String() string {
425+
s, _ := c.MarshalJSON()
426+
return string(s)
427+
}
428+
421429
// The following fields correspond 1:1 with the JSON schema for Config.
422430
type configJSON struct {
423431
XDSServers []*ServerConfig `json:"xds_servers,omitempty"`
@@ -438,7 +446,7 @@ func (c *Config) MarshalJSON() ([]byte, error) {
438446
Authorities: c.authorities,
439447
Node: c.node,
440448
}
441-
return json.Marshal(config)
449+
return json.MarshalIndent(config, " ", " ")
442450
}
443451

444452
// UnmarshalJSON takes the json data (the complete bootstrap configuration) and
@@ -566,9 +574,7 @@ func newConfigFromContents(data []byte) (*Config, error) {
566574
}
567575

568576
if logger.V(2) {
569-
logger.Infof("Bootstrap config for creating xds-client: %v", pretty.ToJSON(config))
570-
} else {
571-
logger.Infof("Bootstrap config for creating xds-client: %+v", config)
577+
logger.Infof("Bootstrap config for creating xds-client: %s", config)
572578
}
573579
return config, nil
574580
}
@@ -632,7 +638,7 @@ func NewContentsForTesting(opts ConfigOptionsForTesting) ([]byte, error) {
632638
Authorities: authorities,
633639
Node: node{ID: opts.NodeID},
634640
}
635-
contents, err := json.Marshal(cfgJSON)
641+
contents, err := json.MarshalIndent(cfgJSON, " ", " ")
636642
if err != nil {
637643
return nil, fmt.Errorf("failed to marshal bootstrap configuration for provided options %+v: %v", opts, err)
638644
}

xds/csds/csds.go

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"context"
2828
"fmt"
2929
"io"
30-
"sync"
3130

3231
"google.golang.org/grpc/codes"
3332
"google.golang.org/grpc/grpclog"
@@ -55,22 +54,14 @@ func prefixLogger(s *ClientStatusDiscoveryServer) *internalgrpclog.PrefixLogger
5554
// https://github.com/grpc/proposal/blob/master/A40-csds-support.md.
5655
type ClientStatusDiscoveryServer struct {
5756
logger *internalgrpclog.PrefixLogger
58-
59-
mu sync.Mutex
60-
xdsClient xdsclient.XDSClient
61-
xdsClientClose func()
6257
}
6358

6459
// NewClientStatusDiscoveryServer returns an implementation of the CSDS server
6560
// that can be registered on a gRPC server.
6661
func NewClientStatusDiscoveryServer() (*ClientStatusDiscoveryServer, error) {
67-
c, close, err := xdsclient.New()
68-
if err != nil {
69-
logger.Warningf("Failed to create xDS client: %v", err)
70-
}
71-
s := &ClientStatusDiscoveryServer{xdsClient: c, xdsClientClose: close}
62+
s := &ClientStatusDiscoveryServer{}
7263
s.logger = prefixLogger(s)
73-
s.logger.Infof("Created CSDS server, with xdsClient %p", c)
64+
s.logger.Infof("Created CSDS server")
7465
return s, nil
7566
}
7667

@@ -104,24 +95,14 @@ func (s *ClientStatusDiscoveryServer) FetchClientStatus(_ context.Context, req *
10495
//
10596
// If it returns an error, the error is a status error.
10697
func (s *ClientStatusDiscoveryServer) buildClientStatusRespForReq(req *v3statuspb.ClientStatusRequest) (*v3statuspb.ClientStatusResponse, error) {
107-
s.mu.Lock()
108-
defer s.mu.Unlock()
109-
110-
if s.xdsClient == nil {
111-
return &v3statuspb.ClientStatusResponse{}, nil
112-
}
11398
// Field NodeMatchers is unsupported, by design
11499
// https://github.com/grpc/proposal/blob/master/A40-csds-support.md#detail-node-matching.
115100
if len(req.NodeMatchers) != 0 {
116101
return nil, status.Errorf(codes.InvalidArgument, "node_matchers are not supported, request contains node_matchers: %v", req.NodeMatchers)
117102
}
118103

119-
return s.xdsClient.DumpResources()
104+
return xdsclient.DumpResources(), nil
120105
}
121106

122107
// Close cleans up the resources.
123-
func (s *ClientStatusDiscoveryServer) Close() {
124-
if s.xdsClientClose != nil {
125-
s.xdsClientClose()
126-
}
127-
}
108+
func (s *ClientStatusDiscoveryServer) Close() {}

0 commit comments

Comments
 (0)