Skip to content

Commit

Permalink
Merge pull request #6157 from mikutas/6156-informer
Browse files Browse the repository at this point in the history
Fix multiple run of informers created in fetcher.go
  • Loading branch information
k8s-ci-robot authored Oct 18, 2023
2 parents cc888a1 + e56c2d8 commit dab41cc
Showing 1 changed file with 6 additions and 7 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,13 +56,11 @@ 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 {
return nil, fmt.Errorf("informer did not sync")
}
return &limitsChecker{limitRangeLister}, nil
}
Expand Down

0 comments on commit dab41cc

Please sign in to comment.