mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 16:54:15 -04:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user