diff options
author | 2021-03-26 08:54:39 -0400 | |
---|---|---|
committer | 2021-03-26 08:54:39 -0400 | |
commit | 9f72db12e73d6f1b7f69812baa4381fc7a1f04b3 (patch) | |
tree | e97d2b76c4c7ad75dbd4213d77f69cc0f6a8b1b3 /plugin/kubernetes/setup.go | |
parent | ea41dd23a01d653b01d153a868d586fac4d4381a (diff) | |
download | coredns-9f72db12e73d6f1b7f69812baa4381fc7a1f04b3.tar.gz coredns-9f72db12e73d6f1b7f69812baa4381fc7a1f04b3.tar.zst coredns-9f72db12e73d6f1b7f69812baa4381fc7a1f04b3.zip |
plugin/kubernetes: do endpoint/slice check in retry loop (#4492)
* do endpoint/slice check in retry loop
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Diffstat (limited to 'plugin/kubernetes/setup.go')
-rw-r--r-- | plugin/kubernetes/setup.go | 36 |
1 files changed, 7 insertions, 29 deletions
diff --git a/plugin/kubernetes/setup.go b/plugin/kubernetes/setup.go index 89ec439fb..8b9bd2c42 100644 --- a/plugin/kubernetes/setup.go +++ b/plugin/kubernetes/setup.go @@ -7,7 +7,6 @@ import ( "os" "strconv" "strings" - "time" "github.com/coredns/caddy" "github.com/coredns/coredns/core/dnsserver" @@ -39,12 +38,16 @@ func setup(c *caddy.Controller) error { return plugin.Error(pluginName, err) } - err = k.InitKubeCache(context.Background()) + onStart, onShut, err := k.InitKubeCache(context.Background()) if err != nil { return plugin.Error(pluginName, err) } - - k.RegisterKubeCache(c) + if onStart != nil { + c.OnStartup(onStart) + } + if onShut != nil { + c.OnShutdown(onShut) + } dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler { k.Next = next @@ -60,30 +63,6 @@ func setup(c *caddy.Controller) error { return nil } -// RegisterKubeCache registers KubeCache start and stop functions with Caddy -func (k *Kubernetes) RegisterKubeCache(c *caddy.Controller) { - c.OnStartup(func() error { - go k.APIConn.Run() - - timeout := time.After(5 * time.Second) - ticker := time.NewTicker(100 * time.Millisecond) - for { - select { - case <-ticker.C: - if k.APIConn.HasSynced() { - return nil - } - case <-timeout: - return nil - } - } - }) - - c.OnShutdown(func() error { - return k.APIConn.Stop() - }) -} - func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) { var ( k8s *Kubernetes @@ -113,7 +92,6 @@ func ParseStanza(c *caddy.Controller) (*Kubernetes, error) { opts := dnsControlOpts{ initEndpointsCache: true, - useEndpointSlices: false, ignoreEmptyService: false, } k8s.opts = opts |