Skip to content

Commit

Permalink
avoid sharedIndexInformer run more than once, avoid more cache and me…
Browse files Browse the repository at this point in the history
…mory consume

Kubernetes-commit: 305c13faca48d1a6ea4d263e262ebc8df0387c84
  • Loading branch information
kitianFresh authored and k8s-publishing-bot committed Sep 9, 2021
1 parent b36b60b commit f0bcda0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tools/cache/shared_informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ func (s *sharedIndexInformer) SetWatchErrorHandler(handler WatchErrorHandler) er
func (s *sharedIndexInformer) Run(stopCh <-chan struct{}) {
defer utilruntime.HandleCrash()

if s.HasStarted() {
klog.Warningf("The sharedIndexInformer has started, run more than once is not allowed")
return
}
fifo := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
KnownObjects: s.indexer,
EmitDeltaTypeReplaced: true,
Expand Down Expand Up @@ -410,6 +414,12 @@ func (s *sharedIndexInformer) Run(stopCh <-chan struct{}) {
s.controller.Run(stopCh)
}

func (s *sharedIndexInformer) HasStarted() bool {
s.startedLock.Lock()
defer s.startedLock.Unlock()
return s.started
}

func (s *sharedIndexInformer) HasSynced() bool {
s.startedLock.Lock()
defer s.startedLock.Unlock()
Expand Down

0 comments on commit f0bcda0

Please sign in to comment.