@@ -289,38 +289,43 @@ func loadConfigMapVerifierDataFromUpdate(update *payload.Update, clientBuilder s
289289 return verifier , persister , nil
290290}
291291
292- // Run runs the cluster version operator until stopCh is completed. Workers is ignored for now.
293- func (optr * Operator ) Run (ctx context.Context , workers int ) error {
292+ // Run runs the cluster version operator until runContext.Done() and
293+ // then attempts a clean shutdown limited by shutdownContext.Done().
294+ // Assumes runContext.Done() occurs before or simultaneously with
295+ // shutdownContext.Done().
296+ func (optr * Operator ) Run (runContext context.Context , shutdownContext context.Context , workers int ) error {
294297 defer optr .queue .ShutDown ()
295- stopCh := ctx .Done ()
298+ stopCh := runContext .Done ()
296299 workerStopCh := make (chan struct {})
297300
298301 klog .Infof ("Starting ClusterVersionOperator with minimum reconcile period %s" , optr .minimumUpdateCheckInterval )
299302 defer klog .Info ("Shutting down ClusterVersionOperator" )
300303
301304 if ! cache .WaitForCacheSync (stopCh , optr .cacheSynced ... ) {
302- return fmt .Errorf ("caches never synchronized: %w" , ctx .Err ())
305+ return fmt .Errorf ("caches never synchronized: %w" , runContext .Err ())
303306 }
304307
305308 // trigger the first cluster version reconcile always
306309 optr .queue .Add (optr .queueKey ())
307310
308311 // start the config sync loop, and have it notify the queue when new status is detected
309- go runThrottledStatusNotifier (ctx , optr .statusInterval , 2 , optr .configSync .StatusCh (), func () { optr .queue .Add (optr .queueKey ()) })
310- go optr .configSync .Start (ctx , 16 , optr .name , optr .cvLister )
311- go wait .UntilWithContext (ctx , func (ctx context.Context ) { optr .worker (ctx , optr .availableUpdatesQueue , optr .availableUpdatesSync ) }, time .Second )
312- go wait .UntilWithContext (ctx , func (ctx context.Context ) { optr .worker (ctx , optr .upgradeableQueue , optr .upgradeableSync ) }, time .Second )
313- go wait .UntilWithContext (ctx , func (ctx context.Context ) {
312+ go runThrottledStatusNotifier (runContext , optr .statusInterval , 2 , optr .configSync .StatusCh (), func () { optr .queue .Add (optr .queueKey ()) })
313+ go optr .configSync .Start (runContext , 16 , optr .name , optr .cvLister )
314+ go wait .UntilWithContext (runContext , func (runContext context.Context ) {
315+ optr .worker (runContext , optr .availableUpdatesQueue , optr .availableUpdatesSync )
316+ }, time .Second )
317+ go wait .UntilWithContext (runContext , func (runContext context.Context ) { optr .worker (runContext , optr .upgradeableQueue , optr .upgradeableSync ) }, time .Second )
318+ go wait .UntilWithContext (runContext , func (runContext context.Context ) {
314319 defer close (workerStopCh )
315320
316321 // run the worker, then when the queue is closed sync one final time to flush any pending status
317- optr .worker (ctx , optr .queue , func (ctx context.Context , key string ) error { return optr .sync (ctx , key ) })
318- if err := optr .sync (ctx , optr .queueKey ()); err != nil {
322+ optr .worker (runContext , optr .queue , func (runContext context.Context , key string ) error { return optr .sync (runContext , key ) })
323+ if err := optr .sync (shutdownContext , optr .queueKey ()); err != nil {
319324 utilruntime .HandleError (fmt .Errorf ("unable to perform final sync: %v" , err ))
320325 }
321326 }, time .Second )
322327 if optr .signatureStore != nil {
323- go optr .signatureStore .Run (ctx , optr .minimumUpdateCheckInterval * 2 )
328+ go optr .signatureStore .Run (runContext , optr .minimumUpdateCheckInterval * 2 )
324329 }
325330
326331 <- stopCh
0 commit comments