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 12cb8a7
Show file tree
Hide file tree
Showing 34 changed files with 600 additions and 365 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
5 changes: 3 additions & 2 deletions xds/internal/resolver/xds_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ const Scheme = "xds"

// newBuilderWithConfigForTesting creates a new xds resolver builder using a
// specific xds bootstrap config, so tests can use multiple xds clients in
// different ClientConns at the same time.
// different ClientConns at the same time. It creates the new xds client int
// the default pool with provided config.
func newBuilderWithConfigForTesting(config []byte) (resolver.Builder, error) {
return &xdsResolverBuilder{
newXDSClient: func(name string) (xdsclient.XDSClient, func(), error) {
return xdsclient.NewForTesting(xdsclient.OptionsForTesting{Name: name, Contents: config})
return xdsclient.DefaultPool.NewClientForTesting(xdsclient.OptionsForTesting{Name: name, Contents: config})
},
}, 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 12cb8a7

Please sign in to comment.