mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-29 08:29:23 +00:00
avoid sharedIndexInformer run more than once, avoid more cache and memory consume
Kubernetes-commit: 305c13faca48d1a6ea4d263e262ebc8df0387c84
This commit is contained in:
parent
b36b60b678
commit
f0bcda0dce
10
tools/cache/shared_informer.go
vendored
10
tools/cache/shared_informer.go
vendored
@ -368,6 +368,10 @@ func (s *sharedIndexInformer) SetWatchErrorHandler(handler WatchErrorHandler) er
|
|||||||
func (s *sharedIndexInformer) Run(stopCh <-chan struct{}) {
|
func (s *sharedIndexInformer) Run(stopCh <-chan struct{}) {
|
||||||
defer utilruntime.HandleCrash()
|
defer utilruntime.HandleCrash()
|
||||||
|
|
||||||
|
if s.HasStarted() {
|
||||||
|
klog.Warningf("The sharedIndexInformer has started, run more than once is not allowed")
|
||||||
|
return
|
||||||
|
}
|
||||||
fifo := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
|
fifo := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
|
||||||
KnownObjects: s.indexer,
|
KnownObjects: s.indexer,
|
||||||
EmitDeltaTypeReplaced: true,
|
EmitDeltaTypeReplaced: true,
|
||||||
@ -410,6 +414,12 @@ func (s *sharedIndexInformer) Run(stopCh <-chan struct{}) {
|
|||||||
s.controller.Run(stopCh)
|
s.controller.Run(stopCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *sharedIndexInformer) HasStarted() bool {
|
||||||
|
s.startedLock.Lock()
|
||||||
|
defer s.startedLock.Unlock()
|
||||||
|
return s.started
|
||||||
|
}
|
||||||
|
|
||||||
func (s *sharedIndexInformer) HasSynced() bool {
|
func (s *sharedIndexInformer) HasSynced() bool {
|
||||||
s.startedLock.Lock()
|
s.startedLock.Lock()
|
||||||
defer s.startedLock.Unlock()
|
defer s.startedLock.Unlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user