Merge pull request #25669 from deads2k/fix-npe

Automatic merge from submit-queue

prevent nil pointer when starting controllers before running the shar…

Fixes https://github.com/kubernetes/kubernetes/issues/25643.

https://github.com/kubernetes/kubernetes/pull/23795 changed initialization order, so the controller isn't guaranteed to be present at startup.

@mqliang @wojtek-t I'm pretty sure that we're not guaranteed to get back the correct `cache.Indexer` or `cache.Store` either.  I'll look at re-plumbing the `AddIndexer` path to use the same instance so that its safe to use again.
This commit is contained in:
k8s-merge-robot 2016-05-17 07:54:12 -07:00
commit a24f03c3c9

View File

@ -139,11 +139,12 @@ func (s *sharedIndexInformer) Run(stopCh <-chan struct{}) {
Process: s.HandleDeltas,
}
s.controller = New(cfg)
func() {
s.startedLock.Lock()
defer s.startedLock.Unlock()
s.controller = New(cfg)
s.started = true
}()
@ -158,6 +159,12 @@ func (s *sharedIndexInformer) isStarted() bool {
}
func (s *sharedIndexInformer) HasSynced() bool {
s.startedLock.Lock()
defer s.startedLock.Unlock()
if s.controller == nil {
return false
}
return s.controller.HasSynced()
}