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.
This commit is contained in:
Patrick Ohly 2023-03-01 15:00:30 +01:00
parent a023a5eb17
commit 106fce6fae
2 changed files with 4 additions and 8 deletions

View File

@ -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() {

View File

@ -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 {