Skip to content

Commit

Permalink
use a pool to isolate xds clients with different bootstrap contents f…
Browse files Browse the repository at this point in the history
…or same server
  • Loading branch information
purnesh42H committed Dec 4, 2024
1 parent 4cee077 commit b561f1c
Show file tree
Hide file tree
Showing 33 changed files with 568 additions and 362 deletions.
87 changes: 0 additions & 87 deletions examples/features/gracefulstop/server/main.go

This file was deleted.

8 changes: 4 additions & 4 deletions xds/csds/csds_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (s) TestCSDS(t *testing.T) {
// Create two xDS clients, with different names. These should end up
// creating two different xDS clients.
const xdsClient1Name = "xds-csds-client-1"
xdsClient1, xdsClose1, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
xdsClient1, xdsClose1, err := xdsclient.DefaultPool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: xdsClient1Name,
Contents: bootstrapContents,
})
Expand All @@ -233,7 +233,7 @@ func (s) TestCSDS(t *testing.T) {
}
defer xdsClose1()
const xdsClient2Name = "xds-csds-client-2"
xdsClient2, xdsClose2, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
xdsClient2, xdsClose2, err := xdsclient.DefaultPool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: xdsClient2Name,
Contents: bootstrapContents,
})
Expand Down Expand Up @@ -421,7 +421,7 @@ func (s) TestCSDS_NACK(t *testing.T) {
// Create two xDS clients, with different names. These should end up
// creating two different xDS clients.
const xdsClient1Name = "xds-csds-client-1"
xdsClient1, xdsClose1, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
xdsClient1, xdsClose1, err := xdsclient.DefaultPool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: xdsClient1Name,
Contents: bootstrapContents,
})
Expand All @@ -430,7 +430,7 @@ func (s) TestCSDS_NACK(t *testing.T) {
}
defer xdsClose1()
const xdsClient2Name = "xds-csds-client-2"
xdsClient2, xdsClose2, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
xdsClient2, xdsClose2, err := xdsclient.DefaultPool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: xdsClient2Name,
Contents: bootstrapContents,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ func registerWrappedCDSPolicyWithNewSubConnOverride(t *testing.T, ch chan *xdscr
func setupForSecurityTests(t *testing.T, bootstrapContents []byte, clientCreds, serverCreds credentials.TransportCredentials) (*grpc.ClientConn, string) {
t.Helper()

xdsClient, xdsClose, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
Contents: bootstrapContents,
pool, err := xdsclient.NewPool(bootstrapContents)
if err != nil {
t.Fatalf("Failed to create an xDS client pool: %v", err)
}
xdsClient, xdsClose, err := pool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
})
if err != nil {
t.Fatalf("Failed to create xDS client: %v", err)
Expand Down
18 changes: 12 additions & 6 deletions xds/internal/balancer/cdsbalancer/cdsbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,12 @@ func setupWithManagementServer(t *testing.T) (*e2e.ManagementServer, string, *gr
nodeID := uuid.New().String()
bc := e2e.DefaultBootstrapContents(t, nodeID, mgmtServer.Address)

xdsC, xdsClose, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
Contents: bc,
pool, err := xdsclient.NewPool(bc)
if err != nil {
t.Fatalf("Failed to create an xDS client pool: %v", err)
}
xdsC, xdsClose, err := pool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
})
if err != nil {
t.Fatalf("Failed to create xDS client: %v", err)
Expand Down Expand Up @@ -356,9 +359,12 @@ func (s) TestConfigurationUpdate_EmptyCluster(t *testing.T) {
nodeID := uuid.New().String()
bc := e2e.DefaultBootstrapContents(t, nodeID, mgmtServer.Address)

xdsClient, xdsClose, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
Contents: bc,
pool, err := xdsclient.NewPool(bc)
if err != nil {
t.Fatalf("Failed to create an xDS client pool: %v", err)
}
xdsClient, xdsClose, err := pool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
})
if err != nil {
t.Fatalf("Failed to create xDS client: %v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,9 +1180,12 @@ func (s) TestAggregateCluster_Fallback_EDS_ResourceNotFound(t *testing.T) {

// Create an xDS client talking to the above management server, configured
// with a short watch expiry timeout.
xdsClient, close, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
pool, err := xdsclient.NewPool(bootstrapContents)
if err != nil {
t.Fatalf("Failed to create an xDS client pool: %v", err)
}
xdsClient, close, err := pool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
Contents: bootstrapContents,
WatchExpiryTimeout: defaultTestWatchExpiryTimeout,
})
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ func setupAndDial(t *testing.T, bootstrapContents []byte) (*grpc.ClientConn, fun
t.Helper()

// Create an xDS client for use by the cluster_resolver LB policy.
xdsC, xdsClose, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
Contents: bootstrapContents,
pool, err := xdsclient.NewPool(bootstrapContents)
if err != nil {
t.Fatalf("Failed to create an xDS client pool: %v", err)
}
xdsC, xdsClose, err := pool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
})
if err != nil {
t.Fatalf("Failed to create xDS client: %v", err)
Expand Down
61 changes: 41 additions & 20 deletions xds/internal/balancer/clusterresolver/e2e_test/eds_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ func (s) TestEDS_OneLocality(t *testing.T) {
}

// Create an xDS client for use by the cluster_resolver LB policy.
client, close, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
Contents: bootstrapContents,
pool, err := xdsclient.NewPool(bootstrapContents)
if err != nil {
t.Fatalf("Failed to create an xDS client pool: %v", err)
}
client, close, err := pool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
})
if err != nil {
t.Fatalf("Failed to create xDS client: %v", err)
Expand Down Expand Up @@ -285,9 +288,12 @@ func (s) TestEDS_MultipleLocalities(t *testing.T) {
}

// Create an xDS client for use by the cluster_resolver LB policy.
client, close, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
Contents: bootstrapContents,
pool, err := xdsclient.NewPool(bootstrapContents)
if err != nil {
t.Fatalf("Failed to create an xDS client pool: %v", err)
}
client, close, err := pool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
})
if err != nil {
t.Fatalf("Failed to create xDS client: %v", err)
Expand Down Expand Up @@ -449,9 +455,12 @@ func (s) TestEDS_EndpointsHealth(t *testing.T) {
}

// Create an xDS client for use by the cluster_resolver LB policy.
client, close, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
Contents: bootstrapContents,
pool, err := xdsclient.NewPool(bootstrapContents)
if err != nil {
t.Fatalf("Failed to create an xDS client pool: %v", err)
}
client, close, err := pool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
})
if err != nil {
t.Fatalf("Failed to create xDS client: %v", err)
Expand Down Expand Up @@ -522,9 +531,12 @@ func (s) TestEDS_EmptyUpdate(t *testing.T) {
}

// Create an xDS client for use by the cluster_resolver LB policy.
client, close, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
Contents: bootstrapContents,
pool, err := xdsclient.NewPool(bootstrapContents)
if err != nil {
t.Fatalf("Failed to create an xDS client pool: %v", err)
}
client, close, err := pool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
})
if err != nil {
t.Fatalf("Failed to create xDS client: %v", err)
Expand Down Expand Up @@ -921,9 +933,12 @@ func (s) TestEDS_BadUpdateWithoutPreviousGoodUpdate(t *testing.T) {
}

// Create an xDS client for use by the cluster_resolver LB policy.
xdsClient, close, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
Contents: bootstrapContents,
pool, err := xdsclient.NewPool(bootstrapContents)
if err != nil {
t.Fatalf("Failed to create an xDS client pool: %v", err)
}
xdsClient, close, err := pool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
})
if err != nil {
t.Fatalf("Failed to create xDS client: %v", err)
Expand Down Expand Up @@ -993,9 +1008,12 @@ func (s) TestEDS_BadUpdateWithPreviousGoodUpdate(t *testing.T) {
}

// Create an xDS client for use by the cluster_resolver LB policy.
xdsClient, close, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
Contents: bootstrapContents,
pool, err := xdsclient.NewPool(bootstrapContents)
if err != nil {
t.Fatalf("Failed to create an xDS client pool: %v", err)
}
xdsClient, close, err := pool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
})
if err != nil {
t.Fatalf("Failed to create xDS client: %v", err)
Expand Down Expand Up @@ -1065,9 +1083,12 @@ func (s) TestEDS_ResourceNotFound(t *testing.T) {
// with a short watch expiry timeout.
nodeID := uuid.New().String()
bc := e2e.DefaultBootstrapContents(t, nodeID, mgmtServer.Address)
xdsClient, close, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
pool, err := xdsclient.NewPool(bc)
if err != nil {
t.Fatalf("Failed to create an xDS client pool: %v", err)
}
xdsClient, close, err := pool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
Contents: bc,
WatchExpiryTimeout: defaultTestWatchExpiryTimeout,
})
if err != nil {
Expand Down
17 changes: 16 additions & 1 deletion xds/internal/resolver/xds_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,24 @@ const Scheme = "xds"
// specific xds bootstrap config, so tests can use multiple xds clients in
// different ClientConns at the same time.
func newBuilderWithConfigForTesting(config []byte) (resolver.Builder, error) {
pool, err := xdsclient.NewPool(config)
if err != nil {
return nil, fmt.Errorf("failed to create an xDS client pool: %v", err)
}

Check warning on line 54 in xds/internal/resolver/xds_resolver.go

View check run for this annotation

Codecov / codecov/patch

xds/internal/resolver/xds_resolver.go#L53-L54

Added lines #L53 - L54 were not covered by tests
return &xdsResolverBuilder{
newXDSClient: func(name string) (xdsclient.XDSClient, func(), error) {
return pool.NewClientForTesting(xdsclient.OptionsForTesting{Name: name})
},
}, nil
}

// newBuilderWithConfigForTesting creates a new xds resolver builder using a
// specific `xdsclient.Pool`, so tests can use multiple pools of clients in
// which each can be initialized with different bootstrap contents.
func newBuilderWithPoolForTesting(pool *xdsclient.Pool) (resolver.Builder, error) {

Check warning on line 65 in xds/internal/resolver/xds_resolver.go

View check run for this annotation

Codecov / codecov/patch

xds/internal/resolver/xds_resolver.go#L65

Added line #L65 was not covered by tests
return &xdsResolverBuilder{
newXDSClient: func(name string) (xdsclient.XDSClient, func(), error) {
return xdsclient.NewForTesting(xdsclient.OptionsForTesting{Name: name, Contents: config})
return pool.NewClientForTesting(xdsclient.OptionsForTesting{Name: name})

Check warning on line 68 in xds/internal/resolver/xds_resolver.go

View check run for this annotation

Codecov / codecov/patch

xds/internal/resolver/xds_resolver.go#L68

Added line #L68 was not covered by tests
},
}, nil
}
Expand Down
7 changes: 5 additions & 2 deletions xds/internal/resolver/xds_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,12 @@ func (s) TestResolverCloseClosesXDSClient(t *testing.T) {
closeCh := make(chan struct{})
rinternal.NewXDSClient = func(string) (xdsclient.XDSClient, func(), error) {
bc := e2e.DefaultBootstrapContents(t, uuid.New().String(), "dummy-management-server-address")
c, cancel, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
pool, err := xdsclient.NewPool(bc)
if err != nil {
t.Fatalf("Failed to create an xDS client pool: %v", err)
}
c, cancel, err := pool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
Contents: bc,
WatchExpiryTimeout: defaultTestTimeout,
})
return c, grpcsync.OnceFunc(func() {
Expand Down
9 changes: 6 additions & 3 deletions xds/internal/server/rds_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@ func xdsSetupForTests(t *testing.T) (*e2e.ManagementServer, string, chan []strin
nodeID := uuid.New().String()
bootstrapContents := e2e.DefaultBootstrapContents(t, nodeID, mgmtServer.Address)

xdsC, cancel, err := xdsclient.NewForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
Contents: bootstrapContents,
pool, err := xdsclient.NewPool(bootstrapContents)
if err != nil {
t.Fatalf("Failed to create an xDS client pool: %v", err)
}
xdsC, cancel, err := pool.NewClientForTesting(xdsclient.OptionsForTesting{
Name: t.Name(),
})
if err != nil {
t.Fatal(err)
Expand Down
Loading

0 comments on commit b561f1c

Please sign in to comment.