From d64b684831aff2df86d9cea8e23bf57c85b6772f Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Fri, 20 Oct 2017 22:53:17 +0100 Subject: 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 --- plugin/kubernetes/controller.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'plugin/kubernetes/controller.go') diff --git a/plugin/kubernetes/controller.go b/plugin/kubernetes/controller.go index a3145bf3d..3cad9e6c2 100644 --- a/plugin/kubernetes/controller.go +++ b/plugin/kubernetes/controller.go @@ -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 { -- cgit v1.2.3