forked from yusheng-guo/kube-metrics-adapter
Prevent leaking collectors when HPA gets updated (#54)
* Prevent leaking collectors when HPA gets updated This fixes an issue where collectors would be leaking when HPAs are getting updated. Fix this by stopping the collector started for the previous version of the HPA. Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de> * Add tests to verify old collector is removed Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
This commit is contained in:

committed by
Sandor Szücs

parent
5598b4d012
commit
ffff8c2040
@@ -132,7 +132,16 @@ func (p *HPAProvider) updateHPAs() error {
|
||||
Namespace: hpa.Namespace,
|
||||
}
|
||||
|
||||
if cachedHPA, ok := p.hpaCache[resourceRef]; !ok || !equalHPA(cachedHPA, hpa) {
|
||||
cachedHPA, ok := p.hpaCache[resourceRef]
|
||||
hpaUpdated := !equalHPA(cachedHPA, hpa)
|
||||
if !ok || hpaUpdated {
|
||||
// if the hpa has changed then remove the previous
|
||||
// scheduled collector.
|
||||
if hpaUpdated {
|
||||
p.logger.Infof("Removing previously scheduled metrics collector: %s", resourceRef)
|
||||
p.collectorScheduler.Remove(resourceRef)
|
||||
}
|
||||
|
||||
metricConfigs, err := collector.ParseHPAMetrics(&hpa)
|
||||
if err != nil {
|
||||
p.logger.Errorf("Failed to parse HPA metrics: %v", err)
|
||||
|
Reference in New Issue
Block a user