Have quota controller use a rate limiter to avoid hot-loops

This commit is contained in:
derekwaynecarr 2016-05-17 11:09:30 -04:00
parent 959e6ca6b1
commit 3075d8554f

View File

@ -62,7 +62,7 @@ type ResourceQuotaController struct {
// Watches changes to all resource quota // Watches changes to all resource quota
rqController *framework.Controller rqController *framework.Controller
// ResourceQuota objects that need to be synchronized // ResourceQuota objects that need to be synchronized
queue *workqueue.Type queue workqueue.RateLimitingInterface
// To allow injection of syncUsage for testing. // To allow injection of syncUsage for testing.
syncHandler func(key string) error syncHandler func(key string) error
// function that controls full recalculation of quota usage // function that controls full recalculation of quota usage
@ -77,7 +77,7 @@ func NewResourceQuotaController(options *ResourceQuotaControllerOptions) *Resour
// build the resource quota controller // build the resource quota controller
rq := &ResourceQuotaController{ rq := &ResourceQuotaController{
kubeClient: options.KubeClient, kubeClient: options.KubeClient,
queue: workqueue.New(), queue: workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()),
resyncPeriod: options.ResyncPeriod, resyncPeriod: options.ResyncPeriod,
registry: options.Registry, registry: options.Registry,
replenishmentControllers: []framework.ControllerInterface{}, replenishmentControllers: []framework.ControllerInterface{},
@ -170,10 +170,12 @@ func (rq *ResourceQuotaController) worker() {
} }
defer rq.queue.Done(key) defer rq.queue.Done(key)
err := rq.syncHandler(key.(string)) err := rq.syncHandler(key.(string))
if err != nil { if err == nil {
utilruntime.HandleError(err) rq.queue.Forget(key)
rq.queue.Add(key) return false
} }
utilruntime.HandleError(err)
rq.queue.AddRateLimited(key)
return false return false
} }
for { for {