Merge pull request #138481 from carlory/fix-broken-graceful-leader-transition

controller/resourcepoolstatusrequest: Improve goroutine mgmt
This commit is contained in:
Kubernetes Prow Robot 2026-05-15 20:22:30 +05:30 committed by GitHub
commit 016a2bcfa4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -20,6 +20,7 @@ import (
"context"
"fmt"
"sort"
"sync"
"time"
resourcev1alpha3 "k8s.io/api/resource/v1alpha3"
@ -128,11 +129,17 @@ func NewController(
// Run starts the controller workers.
func (c *Controller) Run(ctx context.Context, workers int) {
defer utilruntime.HandleCrash()
defer c.workqueue.ShutDown()
logger := klog.FromContext(ctx)
logger.Info("Starting ResourcePoolStatusRequest controller")
var wg sync.WaitGroup
defer func() {
logger.Info("Shutting down ResourcePoolStatusRequest controller")
c.workqueue.ShutDown()
wg.Wait()
}()
// Wait for the caches to be synced before starting workers
logger.Info("Waiting for informer caches to sync")
if !cache.WaitForCacheSync(ctx.Done(), c.requestSynced, c.sliceSynced, c.claimSynced) {
@ -142,14 +149,17 @@ func (c *Controller) Run(ctx context.Context, workers int) {
logger.Info("Starting workers", "count", workers)
for range workers {
go wait.UntilWithContext(ctx, c.runWorker, time.Second)
wg.Go(func() {
wait.UntilWithContext(ctx, c.runWorker, time.Second)
})
}
// Start the cleanup goroutine for TTL-based garbage collection
go wait.UntilWithContext(ctx, c.cleanupExpiredRequests, cleanupPollingInterval)
wg.Go(func() {
wait.UntilWithContext(ctx, c.cleanupExpiredRequests, cleanupPollingInterval)
})
<-ctx.Done()
logger.Info("Shutting down ResourcePoolStatusRequest controller")
}
// runWorker is a long-running function that will continually call the