Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xds: add xDS transport custom Dialer support #7586

Merged
merged 10 commits into from
Sep 27, 2024
Prev Previous commit
Next Next commit
address review p5: embed credentials.Bundle interface in tests
  • Loading branch information
danielzhaotongliu committed Sep 18, 2024
commit 65feb3c0088ac9257d2d276d5a9ee2d601d63cd8
15 changes: 2 additions & 13 deletions test/xds/xds_client_custom_dialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (t *testDialerCredsBuilder) Build(config json.RawMessage) (credentials.Bund
if err := json.Unmarshal(config, &cfg); err != nil {
return nil, func() {}, fmt.Errorf("failed to unmarshal config: %v", err)
}
return &testDialerCredsBundle{t.dialerCalled, cfg.MgmtServerAddress}, func() {}, nil
return &testDialerCredsBundle{insecure.NewBundle(), t.dialerCalled, cfg.MgmtServerAddress}, func() {}, nil
}

func (t *testDialerCredsBuilder) Name() string {
Expand All @@ -68,22 +68,11 @@ func (t *testDialerCredsBuilder) Name() string {
// `credentials` and encapsulates an insecure credential with a custom Dialer
// that specifies how to dial the xDS server.
type testDialerCredsBundle struct {
credentials.Bundle
dialerCalled chan struct{}
mgmtServerAddress string
}

func (t *testDialerCredsBundle) TransportCredentials() credentials.TransportCredentials {
return insecure.NewCredentials()
}

func (t *testDialerCredsBundle) PerRPCCredentials() credentials.PerRPCCredentials {
return nil
}

func (t *testDialerCredsBundle) NewWithMode(string) (credentials.Bundle, error) {
return &testDialerCredsBundle{}, nil
}

// Dialer specifies how to dial the xDS management server.
func (t *testDialerCredsBundle) Dialer(context.Context, string) (net.Conn, error) {
close(t.dialerCalled)
Expand Down
21 changes: 4 additions & 17 deletions xds/internal/xdsclient/transport/transport_test.go
easwars marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,13 @@ func (s) TestNewWithGRPCDial(t *testing.T) {

const testDialerCredsBuilderName = "test_dialer_creds"

func init() {
bootstrap.RegisterCredentials(&testDialerCredsBuilder{})
}

// testDialerCredsBuilder implements the `Credentials` interface defined in
// package `xds/bootstrap` and encapsulates an insecure credential with a
// custom Dialer that specifies how to dial the xDS server.
type testDialerCredsBuilder struct{}

func (t *testDialerCredsBuilder) Build(json.RawMessage) (credentials.Bundle, func(), error) {
return &testDialerCredsBundle{}, func() {}, nil
return &testDialerCredsBundle{insecure.NewBundle()}, func() {}, nil
}

func (t *testDialerCredsBuilder) Name() string {
Expand All @@ -111,25 +107,16 @@ func (t *testDialerCredsBuilder) Name() string {
// testDialerCredsBundle implements the `Bundle` interface defined in package
// `credentials` and encapsulates an insecure credential with a custom Dialer
// that specifies how to dial the xDS server.
type testDialerCredsBundle struct{}

func (t *testDialerCredsBundle) TransportCredentials() credentials.TransportCredentials {
return insecure.NewCredentials()
}

func (t *testDialerCredsBundle) PerRPCCredentials() credentials.PerRPCCredentials {
return nil
}

func (t *testDialerCredsBundle) NewWithMode(string) (credentials.Bundle, error) {
return &testDialerCredsBundle{}, nil
type testDialerCredsBundle struct {
credentials.Bundle
}

func (t *testDialerCredsBundle) Dialer(context.Context, string) (net.Conn, error) {
return nil, nil
}

func (s) TestNewWithDialerFromCredentialsBundle(t *testing.T) {
easwars marked this conversation as resolved.
Show resolved Hide resolved
bootstrap.RegisterCredentials(&testDialerCredsBuilder{})
serverCfg, err := internalbootstrap.ServerConfigForTesting(internalbootstrap.ServerConfigTestingOptions{
URI: "trafficdirector.googleapis.com:443",
ChannelCreds: []internalbootstrap.ChannelCreds{{Type: testDialerCredsBuilderName}},
Expand Down