plugin/kubernetes: implement HasSynced() (#1155)

* plugin/kubernetes: wait until api is ready

Wait for HasSynced before allowing startup to avoid startup race.

Also do a small refactor in findServices() to pull a check out of the
loop - only needs to be done once.

* sigh
This commit is contained in:
Miek Gieben
2017-10-20 22:53:17 +01:00
committed by GitHub
parent c1f67493de
commit d64b684831
13 changed files with 36 additions and 41 deletions

View File

@@ -38,6 +38,7 @@ type dnsController interface {
GetNodeByName(string) (*api.Node, error)
Run()
HasSynced() bool
Stop() error
}
@@ -229,17 +230,6 @@ func endpointsWatchFunc(c *kubernetes.Clientset, ns string, s *labels.Selector)
}
}
func (dns *dnsControl) controllersInSync() bool {
hs := dns.svcController.HasSynced() &&
dns.epController.HasSynced()
if dns.podController != nil {
hs = hs && dns.podController.HasSynced()
}
return hs
}
// Stop stops the controller.
func (dns *dnsControl) Stop() error {
dns.stopLock.Lock()
@@ -266,6 +256,17 @@ func (dns *dnsControl) Run() {
<-dns.stopCh
}
// HasSynced calls on all controllers.
func (dns *dnsControl) HasSynced() bool {
a := dns.svcController.HasSynced()
b := dns.epController.HasSynced()
c := true
if dns.podController != nil {
c = dns.podController.HasSynced()
}
return a && b && c
}
func (dns *dnsControl) ServiceList() (svcs []*api.Service) {
os := dns.svcLister.List()
for _, o := range os {