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
This commit is contained in:
parent
10681c6bf0
commit
ea77f2a2ca
7 changed files with 53 additions and 28 deletions
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue