Skip to content

Commit

Permalink
Fix multiple run of informers created in fetcher.go
Browse files Browse the repository at this point in the history
  • Loading branch information
mikutas committed Sep 28, 2023
1 parent 5d00f07 commit 96958f8
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 96958f8

Please sign in to comment.