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 5, 2024
1 parent 4cee077 commit aa7e498
Show file tree
Hide file tree
Showing 31 changed files with 592 additions and 334 deletions.
87 changes: 0 additions & 87 deletions examples/features/gracefulstop/server/main.go

This file was deleted.

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
3 changes: 2 additions & 1 deletion xds/internal/resolver/xds_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ 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) {
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 aa7e498

Please sign in to comment.