Skip to content

Commit dab41cc

Browse files
authored
Merge pull request #6157 from mikutas/6156-informer
Fix multiple run of informers created in fetcher.go
2 parents cc888a1 + e56c2d8 commit dab41cc

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

vertical-pod-autoscaler/pkg/utils/limitrange/limit_range_calculator.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"k8s.io/apimachinery/pkg/labels"
2525
"k8s.io/client-go/informers"
2626
listers "k8s.io/client-go/listers/core/v1"
27+
"k8s.io/client-go/tools/cache"
2728
)
2829

2930
// LimitRangeCalculator calculates limit range items that has the same effect as all limit range items present in the cluster.
@@ -55,13 +56,11 @@ func NewLimitsRangeCalculator(f informers.SharedInformerFactory) (*limitsChecker
5556
}
5657
limitRangeLister := f.Core().V1().LimitRanges().Lister()
5758
stopCh := make(chan struct{})
58-
f.Start(stopCh)
59-
for _, ok := range f.WaitForCacheSync(stopCh) {
60-
if !ok {
61-
if !f.Core().V1().LimitRanges().Informer().HasSynced() {
62-
return nil, fmt.Errorf("informer did not sync")
63-
}
64-
}
59+
informer := f.Core().V1().LimitRanges().Informer()
60+
go informer.Run(stopCh)
61+
ok := cache.WaitForCacheSync(stopCh, informer.HasSynced)
62+
if !ok {
63+
return nil, fmt.Errorf("informer did not sync")
6564
}
6665
return &limitsChecker{limitRangeLister}, nil
6766
}

0 commit comments

Comments
 (0)