From 7498c14218403c9a713f9e0747f2c6794a0da9c7 Mon Sep 17 00:00:00 2001 From: Krzysztof Jastrzebski Date: Mon, 7 Jan 2019 08:56:43 +0100 Subject: [PATCH] Update comments in Horizontal Pod Autoscaler Controller. --- pkg/controller/podautoscaler/horizontal.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/controller/podautoscaler/horizontal.go b/pkg/controller/podautoscaler/horizontal.go index 4517b0d7299..7ab96583715 100644 --- a/pkg/controller/podautoscaler/horizontal.go +++ b/pkg/controller/podautoscaler/horizontal.go @@ -179,7 +179,9 @@ func (a *HorizontalController) enqueueHPA(obj interface{}) { return } - // always add rate-limited so we don't fetch metrics more that once per resync interval + // Requests are always added to queue with resyncPeriod delay. If there's already + // request for the HPA in the queue then a new request is always dropped. Requests spend resync + // interval in queue so HPAs are processed every resync interval. a.queue.AddRateLimited(key) } @@ -211,10 +213,15 @@ func (a *HorizontalController) processNextWorkItem() bool { if err != nil { utilruntime.HandleError(err) } - // Add request processing HPA after resync interval just in case last resync didn't insert - // request into the queue. Request is not inserted into queue by resync if previous one wasn't processed yet. - // This happens quite often because requests from previous resync are removed from the queue at the same moment - // as next resync inserts new requests. + // Add request processing HPA to queue with resyncPeriod delay. + // Requests are always added to queue with resyncPeriod delay. If there's already request + // for the HPA in the queue then a new request is always dropped. Requests spend resyncPeriod + // in queue so HPAs are processed every resyncPeriod. + // Request is added here just in case last resync didn't insert request into the queue. This + // happens quite often because there is race condition between adding request after resyncPeriod + // and removing them from queue. Request can be added by resync before previous request is + // removed from queue. If we didn't add request here then in this case one request would be dropped + // and HPA would processed after 2 x resyncPeriod. if !deleted { a.queue.AddRateLimited(key) }