Skip to content

Commit d9d8f34

Browse files
revert xds: return all ServerConfig dial options together (#7712)
* revert xds: return all ServerConfig dial options together * revert - xdsclient: fix test build breakage
1 parent 5f178a8 commit d9d8f34

File tree

3 files changed

+35
-40
lines changed

3 files changed

+35
-40
lines changed

internal/xds/bootstrap/bootstrap.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,20 @@ func (sc *ServerConfig) ServerFeaturesIgnoreResourceDeletion() bool {
220220
return false
221221
}
222222

223-
// DialOptions returns a slice of all the configured dial options for this
224-
// server.
225-
func (sc *ServerConfig) DialOptions() []grpc.DialOption {
226-
dopts := []grpc.DialOption{sc.credsDialOption}
227-
if sc.dialerOption != nil {
228-
dopts = append(dopts, sc.dialerOption)
229-
}
230-
return dopts
223+
// CredsDialOption returns the first supported transport credentials from the
224+
// configuration, as a dial option.
225+
func (sc *ServerConfig) CredsDialOption() grpc.DialOption {
226+
return sc.credsDialOption
227+
}
228+
229+
// DialerOption returns the Dialer function that specifies how to dial the xDS
230+
// server determined by the first supported credentials from the configuration,
231+
// as a dial option.
232+
//
233+
// TODO(https://github.com/grpc/grpc-go/issues/7661): change ServerConfig type
234+
// to have a single method that returns all configured dial options.
235+
func (sc *ServerConfig) DialerOption() grpc.DialOption {
236+
return sc.dialerOption
231237
}
232238

233239
// Cleanups returns a collection of functions to be called when the xDS client

xds/internal/xdsclient/transport/transport.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,19 @@ func New(opts Options) (*Transport, error) {
192192
return nil, errors.New("missing OnSend callback handler when creating a new transport")
193193
}
194194

195-
// Dial the xDS management server with dial options specified by the server
196-
// configuration and a static keepalive configuration that is common across
197-
// gRPC language implementations.
198-
kpCfg := grpc.WithKeepaliveParams(keepalive.ClientParameters{
199-
Time: 5 * time.Minute,
200-
Timeout: 20 * time.Second,
201-
})
202-
dopts := append([]grpc.DialOption{kpCfg}, opts.ServerCfg.DialOptions()...)
195+
// Dial the xDS management with the passed in credentials.
196+
dopts := []grpc.DialOption{
197+
opts.ServerCfg.CredsDialOption(),
198+
grpc.WithKeepaliveParams(keepalive.ClientParameters{
199+
// We decided to use these sane defaults in all languages, and
200+
// kicked the can down the road as far making these configurable.
201+
Time: 5 * time.Minute,
202+
Timeout: 20 * time.Second,
203+
}),
204+
}
205+
if dialerOpts := opts.ServerCfg.DialerOption(); dialerOpts != nil {
206+
dopts = append(dopts, dialerOpts)
207+
}
203208
grpcNewClient := transportinternal.GRPCNewClient.(func(string, ...grpc.DialOption) (*grpc.ClientConn, error))
204209
cc, err := grpcNewClient(opts.ServerCfg.ServerURI(), dopts...)
205210
if err != nil {

xds/internal/xdsclient/transport/transport_test.go

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"encoding/json"
2323
"net"
2424
"testing"
25-
"time"
2625

2726
"google.golang.org/grpc"
2827
"google.golang.org/grpc/credentials"
@@ -44,8 +43,6 @@ func Test(t *testing.T) {
4443
grpctest.RunSubTests(t, s{})
4544
}
4645

47-
const defaultTestTimeout = 10 * time.Second
48-
4946
var noopRecvHandler = func(_ transport.ResourceUpdate, onDone func()) error {
5047
onDone()
5148
return nil
@@ -111,17 +108,10 @@ const testDialerCredsBuilderName = "test_dialer_creds"
111108
// testDialerCredsBuilder implements the `Credentials` interface defined in
112109
// package `xds/bootstrap` and encapsulates an insecure credential with a
113110
// custom Dialer that specifies how to dial the xDS server.
114-
type testDialerCredsBuilder struct {
115-
// Closed with the custom Dialer is invoked.
116-
// Needs to be passed in by the test.
117-
dialCalled chan struct{}
118-
}
111+
type testDialerCredsBuilder struct{}
119112

120113
func (t *testDialerCredsBuilder) Build(json.RawMessage) (credentials.Bundle, func(), error) {
121-
return &testDialerCredsBundle{
122-
Bundle: insecure.NewBundle(),
123-
dialCalled: t.dialCalled,
124-
}, func() {}, nil
114+
return &testDialerCredsBundle{insecure.NewBundle()}, func() {}, nil
125115
}
126116

127117
func (t *testDialerCredsBuilder) Name() string {
@@ -133,12 +123,10 @@ func (t *testDialerCredsBuilder) Name() string {
133123
// that specifies how to dial the xDS server.
134124
type testDialerCredsBundle struct {
135125
credentials.Bundle
136-
dialCalled chan struct{}
137126
}
138127

139-
func (t *testDialerCredsBundle) Dialer(_ context.Context, address string) (net.Conn, error) {
140-
close(t.dialCalled)
141-
return net.Dial("tcp", address)
128+
func (t *testDialerCredsBundle) Dialer(context.Context, string) (net.Conn, error) {
129+
return nil, nil
142130
}
143131

144132
func (s) TestNewWithDialerFromCredentialsBundle(t *testing.T) {
@@ -152,16 +140,17 @@ func (s) TestNewWithDialerFromCredentialsBundle(t *testing.T) {
152140
internal.GRPCNewClient = customGRPCNewClient
153141
defer func() { internal.GRPCNewClient = oldGRPCNewClient }()
154142

155-
dialCalled := make(chan struct{})
156-
bootstrap.RegisterCredentials(&testDialerCredsBuilder{dialCalled: dialCalled})
143+
bootstrap.RegisterCredentials(&testDialerCredsBuilder{})
157144
serverCfg, err := internalbootstrap.ServerConfigForTesting(internalbootstrap.ServerConfigTestingOptions{
158145
URI: "trafficdirector.googleapis.com:443",
159146
ChannelCreds: []internalbootstrap.ChannelCreds{{Type: testDialerCredsBuilderName}},
160147
})
161148
if err != nil {
162149
t.Fatalf("Failed to create server config for testing: %v", err)
163150
}
164-
151+
if serverCfg.DialerOption() == nil {
152+
t.Fatalf("Dialer for xDS transport in server config for testing is nil, want non-nil")
153+
}
165154
// Create a new transport.
166155
opts := transport.Options{
167156
ServerCfg: serverCfg,
@@ -182,11 +171,6 @@ func (s) TestNewWithDialerFromCredentialsBundle(t *testing.T) {
182171
if err != nil {
183172
t.Fatalf("transport.New(%v) failed: %v", opts, err)
184173
}
185-
select {
186-
case <-dialCalled:
187-
case <-time.After(defaultTestTimeout):
188-
t.Fatal("Timeout when waiting for Dialer() to be invoked")
189-
}
190174
// Verify there are three dial options passed to the custom grpc.NewClient.
191175
// The first is opts.ServerCfg.CredsDialOption(), the second is
192176
// grpc.WithKeepaliveParams(), and the third is opts.ServerCfg.DialerOption()

0 commit comments

Comments
 (0)