From 106fce6fae114710a599cd14becf19468bad28fb Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 1 Mar 2023 15:00:30 +0100 Subject: [PATCH] e2e dra: improve goroutine handling There is an API now to wait for informer factory goroutine termination. While at it, an incorrect comment for mutex locking gets removed. --- test/e2e/dra/deploy.go | 5 +---- test/e2e/dra/test-driver/app/controller.go | 7 +++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/test/e2e/dra/deploy.go b/test/e2e/dra/deploy.go index ffb80764404..bf5cb8e1d82 100644 --- a/test/e2e/dra/deploy.go +++ b/test/e2e/dra/deploy.go @@ -140,10 +140,7 @@ func (d *Driver) SetUp(nodes *Nodes, resources app.Resources) { d.ctx = ctx d.cleanup = append(d.cleanup, cancel) - // The controller is easy: we simply connect to the API server. It - // would be slightly nicer if we had a way to wait for all goroutines, but - // SharedInformerFactory has no API for that. At least we can wait - // for our own goroutine to stop once the context gets cancelled. + // The controller is easy: we simply connect to the API server. d.Controller = app.NewController(d.f.ClientSet, d.Name, resources) d.wg.Add(1) go func() { diff --git a/test/e2e/dra/test-driver/app/controller.go b/test/e2e/dra/test-driver/app/controller.go index 243a62ffef0..6fbae0aabdd 100644 --- a/test/e2e/dra/test-driver/app/controller.go +++ b/test/e2e/dra/test-driver/app/controller.go @@ -58,7 +58,6 @@ type ExampleController struct { resources Resources driverName string - // mutex must be locked at the gRPC call level. mutex sync.Mutex // allocated maps claim.UID to the node (if network-attached) or empty (if not). allocated map[types.UID]string @@ -77,13 +76,13 @@ func NewController(clientset kubernetes.Interface, driverName string, resources return c } -func (c *ExampleController) Run(ctx context.Context, workers int) *ExampleController { +func (c *ExampleController) Run(ctx context.Context, workers int) { informerFactory := informers.NewSharedInformerFactory(c.clientset, 0 /* resync period */) ctrl := controller.New(ctx, c.driverName, c, c.clientset, informerFactory) informerFactory.Start(ctx.Done()) ctrl.Run(workers) - - return c + // If we get here, the context was canceled and we can wait for informer factory goroutines. + informerFactory.Shutdown() } type parameters struct {