From 96958f868a57225437076e6cb24d24967a747367 Mon Sep 17 00:00:00 2001 From: mikutas <23391543+mikutas@users.noreply.github.com> Date: Thu, 28 Sep 2023 13:16:36 +0900 Subject: [PATCH 1/2] Fix multiple run of informers created in fetcher.go --- .../pkg/utils/limitrange/limit_range_calculator.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/vertical-pod-autoscaler/pkg/utils/limitrange/limit_range_calculator.go b/vertical-pod-autoscaler/pkg/utils/limitrange/limit_range_calculator.go index 77dc394979cc..27d5954e66b8 100644 --- a/vertical-pod-autoscaler/pkg/utils/limitrange/limit_range_calculator.go +++ b/vertical-pod-autoscaler/pkg/utils/limitrange/limit_range_calculator.go @@ -24,6 +24,7 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/informers" listers "k8s.io/client-go/listers/core/v1" + "k8s.io/client-go/tools/cache" ) // LimitRangeCalculator calculates limit range items that has the same effect as all limit range items present in the cluster. @@ -55,12 +56,12 @@ func NewLimitsRangeCalculator(f informers.SharedInformerFactory) (*limitsChecker } limitRangeLister := f.Core().V1().LimitRanges().Lister() stopCh := make(chan struct{}) - f.Start(stopCh) - for _, ok := range f.WaitForCacheSync(stopCh) { - if !ok { - if !f.Core().V1().LimitRanges().Informer().HasSynced() { - return nil, fmt.Errorf("informer did not sync") - } + informer := f.Core().V1().LimitRanges().Informer() + go informer.Run(stopCh) + ok := cache.WaitForCacheSync(stopCh, informer.HasSynced) + if !ok { + if !f.Core().V1().LimitRanges().Informer().HasSynced() { + return nil, fmt.Errorf("informer did not sync") } } return &limitsChecker{limitRangeLister}, nil From e56c2d825518140022101f448d682086fc4c8d1f Mon Sep 17 00:00:00 2001 From: mikutas <23391543+mikutas@users.noreply.github.com> Date: Wed, 18 Oct 2023 08:43:04 +0900 Subject: [PATCH 2/2] Remove redundant if branch --- .../pkg/utils/limitrange/limit_range_calculator.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vertical-pod-autoscaler/pkg/utils/limitrange/limit_range_calculator.go b/vertical-pod-autoscaler/pkg/utils/limitrange/limit_range_calculator.go index 27d5954e66b8..e54804a383a9 100644 --- a/vertical-pod-autoscaler/pkg/utils/limitrange/limit_range_calculator.go +++ b/vertical-pod-autoscaler/pkg/utils/limitrange/limit_range_calculator.go @@ -60,9 +60,7 @@ func NewLimitsRangeCalculator(f informers.SharedInformerFactory) (*limitsChecker go informer.Run(stopCh) ok := cache.WaitForCacheSync(stopCh, informer.HasSynced) if !ok { - if !f.Core().V1().LimitRanges().Informer().HasSynced() { - return nil, fmt.Errorf("informer did not sync") - } + return nil, fmt.Errorf("informer did not sync") } return &limitsChecker{limitRangeLister}, nil }