Skip to content

Commit 9c6247d

Browse files
committed
xdsclient: complete refactor and fallback support
1 parent 4115c21 commit 9c6247d

31 files changed

+4110
-2164
lines changed

internal/internal.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ var (
149149
// other features, including the CSDS service.
150150
NewXDSResolverWithConfigForTesting any // func([]byte) (resolver.Builder, error)
151151

152+
// NewXDSResolverWithClientForTesting creates a new xDS resolver builder
153+
// using the provided xDS client instead of creating a new one using the
154+
// bootstrap configuration specified by the supported environment variables.
155+
// The resolver.Builder is meant to be used in conjunction with the
156+
// grpc.WithResolvers DialOption. The resolver.Builder does not take
157+
// ownership of the provided xDS client and it is the responsibility of the
158+
// caller to close the client when no longer required.
159+
//
160+
// Testing Only
161+
//
162+
// This function should ONLY be used for testing and may not work with some
163+
// other features, including the CSDS service.
164+
NewXDSResolverWithClientForTesting any // func(xdsclient.XDSClient) (resolver.Builder, error)
165+
152166
// RegisterRLSClusterSpecifierPluginForTesting registers the RLS Cluster
153167
// Specifier Plugin for testing purposes, regardless of the XDSRLS environment
154168
// variable.

internal/testutils/restartable_listener.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func (l *RestartableListener) Addr() net.Addr {
8181
// Stop closes existing connections on the listener and prevents new connections
8282
// from being accepted.
8383
func (l *RestartableListener) Stop() {
84+
logger.Infof("Stopping restartable listener %q", l.Addr())
8485
l.mu.Lock()
8586
l.stopped = true
8687
for _, conn := range l.conns {
@@ -92,6 +93,7 @@ func (l *RestartableListener) Stop() {
9293

9394
// Restart gets a previously stopped listener to start accepting connections.
9495
func (l *RestartableListener) Restart() {
96+
logger.Infof("Restarting listener %q", l.Addr())
9597
l.mu.Lock()
9698
l.stopped = false
9799
l.mu.Unlock()

internal/testutils/wrappers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (l *ListenerWrapper) Accept() (net.Conn, error) {
5353
}
5454
closeCh := NewChannel()
5555
conn := &ConnWrapper{Conn: c, CloseCh: closeCh}
56-
l.NewConnCh.Send(conn)
56+
l.NewConnCh.Replace(conn)
5757
return conn, nil
5858
}
5959

xds/internal/resolver/xds_resolver.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,34 @@ import (
4444
// xdsresolver.Scheme
4545
const Scheme = "xds"
4646

47-
// newBuilderForTesting creates a new xds resolver builder using a specific xds
48-
// bootstrap config, so tests can use multiple xds clients in different
49-
// ClientConns at the same time.
50-
func newBuilderForTesting(config []byte) (resolver.Builder, error) {
47+
// newBuilderWithConfigForTesting creates a new xds resolver builder using a
48+
// specific xds bootstrap config, so tests can use multiple xds clients in
49+
// different ClientConns at the same time.
50+
func newBuilderWithConfigForTesting(config []byte) (resolver.Builder, error) {
5151
return &xdsResolverBuilder{
5252
newXDSClient: func(name string) (xdsclient.XDSClient, func(), error) {
5353
return xdsclient.NewForTesting(xdsclient.OptionsForTesting{Name: name, Contents: config})
5454
},
5555
}, nil
5656
}
5757

58+
// newBuilderWithClientForTesting creates a new xds resolver builder using the
59+
// specific xDS client, so that tests have complete control over the exact
60+
// specific xDS client being used.
61+
func newBuilderWithClientForTesting(client xdsclient.XDSClient) (resolver.Builder, error) {
62+
return &xdsResolverBuilder{
63+
newXDSClient: func(string) (xdsclient.XDSClient, func(), error) {
64+
// Returning an empty close func here means that the responsibility
65+
// of closing the client lies with the caller.
66+
return client, func() {}, nil
67+
},
68+
}, nil
69+
}
70+
5871
func init() {
5972
resolver.Register(&xdsResolverBuilder{})
60-
internal.NewXDSResolverWithConfigForTesting = newBuilderForTesting
73+
internal.NewXDSResolverWithConfigForTesting = newBuilderWithConfigForTesting
74+
internal.NewXDSResolverWithClientForTesting = newBuilderWithClientForTesting
6175

6276
rinternal.NewWRR = wrr.NewRandom
6377
rinternal.NewXDSClient = xdsclient.New

0 commit comments

Comments
 (0)