diff options
author | 2017-08-10 21:31:36 +0100 | |
---|---|---|
committer | 2017-08-10 21:31:36 +0100 | |
commit | ea77f2a2caea7973615c93b787f98e67ec6f31a3 (patch) | |
tree | 8b8579b2b85e50778549c8b832e9bd91916bbe0b /middleware/autopath/setup.go | |
parent | 10681c6bf0b73bffa039aff45a80982d045ba095 (diff) | |
download | coredns-ea77f2a2caea7973615c93b787f98e67ec6f31a3.tar.gz coredns-ea77f2a2caea7973615c93b787f98e67ec6f31a3.tar.zst coredns-ea77f2a2caea7973615c93b787f98e67ec6f31a3.zip |
core: replace GetMiddleware (#885)
* core: replace GetMiddleware
See the discussion in #881. GetMiddleware would add a `nil` middleware
to the callstack thereby breaking functionality.
This PR drops it in favor of RegisterHandler which is a completely
standalone registry for middleware that want to let it self know to
other middleware.
Currenly *autopath* uses this to call *kubernetes*'s AutoPath method
for dynamic autopathing.
* Drop GetMiddleware
* Register metrics
* drop the panic
Diffstat (limited to 'middleware/autopath/setup.go')
-rw-r--r-- | middleware/autopath/setup.go | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/middleware/autopath/setup.go b/middleware/autopath/setup.go index 804b61855..1855dd440 100644 --- a/middleware/autopath/setup.go +++ b/middleware/autopath/setup.go @@ -5,6 +5,7 @@ import ( "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/middleware" + "github.com/coredns/coredns/middleware/kubernetes" "github.com/mholt/caddy" "github.com/miekg/dns" @@ -19,23 +20,21 @@ func init() { } func setup(c *caddy.Controller) error { - ap, _, err := autoPathParse(c) + ap, mw, err := autoPathParse(c) if err != nil { return middleware.Error("autopath", err) } + // Do this in OnStartup, so all middleware has been initialized. c.OnStartup(func() error { - // Do this in OnStartup, so all middleware has been initialized. // TODO(miek): fabricate test to proof this is not thread safe. - // TODO(miek): disable this for now: See https://github.com/coredns/coredns/issues/881 - /* - switch mw { - case "kubernetes": - if k, ok := m.(kubernetes.Kubernetes); ok { - ap.searchFunc = k.AutoPath - } - } - */ + m := dnsserver.GetConfig(c).GetHandler(mw) + if m == nil { + return nil + } + if k, ok := m.(kubernetes.Kubernetes); ok { + ap.searchFunc = k.AutoPath + } return nil }) @@ -47,6 +46,8 @@ func setup(c *caddy.Controller) error { return nil } +// allowedMiddleware has a list of middleware that can be used by autopath. For this to work, they +// need to register themselves with dnsserver.RegisterHandler. var allowedMiddleware = map[string]bool{ "@kubernetes": true, } |