mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-05-28 04:04:39 -04:00
controller/volume/pvcprotection: Improve goroutine mgmt
Make sure all threads are terminated when Run returns.
This commit is contained in:
parent
ed74779a0f
commit
0caae6f704
1 changed files with 14 additions and 6 deletions
|
|
@ -161,22 +161,30 @@ func NewPVCProtectionController(logger klog.Logger, pvcInformer coreinformers.Pe
|
|||
// Run runs the controller goroutines.
|
||||
func (c *Controller) Run(ctx context.Context, workers int) {
|
||||
defer utilruntime.HandleCrash()
|
||||
defer c.queue.ShutDown()
|
||||
defer c.pvcProcessingStore.namespaceQueue.ShutDown()
|
||||
|
||||
logger := klog.FromContext(ctx)
|
||||
logger.Info("Starting PVC protection controller")
|
||||
defer logger.Info("Shutting down PVC protection controller")
|
||||
|
||||
var wg sync.WaitGroup
|
||||
defer func() {
|
||||
logger.Info("Shutting down PVC protection controller")
|
||||
c.queue.ShutDown()
|
||||
c.pvcProcessingStore.namespaceQueue.ShutDown()
|
||||
wg.Wait()
|
||||
}()
|
||||
|
||||
if !cache.WaitForNamedCacheSyncWithContext(ctx, c.pvcListerSynced, c.podListerSynced) {
|
||||
return
|
||||
}
|
||||
|
||||
go wait.UntilWithContext(ctx, c.runMainWorker, time.Second)
|
||||
wg.Go(func() {
|
||||
wait.UntilWithContext(ctx, c.runMainWorker, time.Second)
|
||||
})
|
||||
for i := 0; i < workers; i++ {
|
||||
go wait.UntilWithContext(ctx, c.runProcessNamespaceWorker, time.Second)
|
||||
wg.Go(func() {
|
||||
wait.UntilWithContext(ctx, c.runProcessNamespaceWorker, time.Second)
|
||||
})
|
||||
}
|
||||
|
||||
<-ctx.Done()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue