mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-02-21 22:57:15 +00:00
controller/ttl: Improve goroutine mgmt
Make sure all threads are terminated when Run returns.
This commit is contained in:
@@ -122,19 +122,26 @@ var (
|
||||
// Run begins watching and syncing.
|
||||
func (ttlc *Controller) Run(ctx context.Context, workers int) {
|
||||
defer utilruntime.HandleCrash()
|
||||
defer ttlc.queue.ShutDown()
|
||||
|
||||
logger := klog.FromContext(ctx)
|
||||
logger.Info("Starting TTL controller")
|
||||
defer logger.Info("Shutting down TTL controller")
|
||||
|
||||
var wg sync.WaitGroup
|
||||
defer func() {
|
||||
logger.Info("Shutting down TTL controller")
|
||||
ttlc.queue.ShutDown()
|
||||
wg.Wait()
|
||||
}()
|
||||
|
||||
if !cache.WaitForNamedCacheSyncWithContext(ctx, ttlc.hasSynced) {
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < workers; i++ {
|
||||
go wait.UntilWithContext(ctx, ttlc.worker, time.Second)
|
||||
wg.Go(func() {
|
||||
wait.UntilWithContext(ctx, ttlc.worker, time.Second)
|
||||
})
|
||||
}
|
||||
|
||||
<-ctx.Done()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user