mirror of
https://github.com/coredns/coredns.git
synced 2025-10-31 18:23:13 -04:00
Instead of hardcoding plugin lists in autopath/health, use interfaces. (#1306)
Switched health and autopath plugin to allow any plugins to be used instead of a hardcoded list. I did not switch federation over since it wasn't obvious that anything other than kubernetes could be used with it. Fixes #1291
This commit is contained in:
committed by
Miek Gieben
parent
99e163c375
commit
a469a17cdf
@@ -19,15 +19,12 @@ autopath [ZONE...] RESOLV-CONF
|
||||
plugin. For instance `@kubernetes`, will call out to the kubernetes plugin (for each
|
||||
query) to retrieve the search list it should use.
|
||||
|
||||
Currently the following set of plugin has implemented *autopath*:
|
||||
|
||||
* *kubernetes*
|
||||
* *erratic*
|
||||
If a plugin implements the `AutoPather` interface then it can be used.
|
||||
|
||||
## Metrics
|
||||
|
||||
|
||||
If monitoring is enabled (via the *prometheus* directive) then the following metric is exported:
|
||||
|
||||
|
||||
* `coredns_autopath_success_count_total{}` - counter of successfully autopath-ed queries.
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -46,6 +46,12 @@ import (
|
||||
// If Func returns a nil slice, no autopathing will be done.
|
||||
type Func func(request.Request) []string
|
||||
|
||||
// AutoPather defines the interface that a plugin should implement in order to be
|
||||
// used by AutoPath.
|
||||
type AutoPather interface {
|
||||
AutoPath(request.Request) []string
|
||||
}
|
||||
|
||||
// AutoPath perform autopath: service side search path completion.
|
||||
type AutoPath struct {
|
||||
Next plugin.Handler
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
|
||||
"github.com/coredns/coredns/core/dnsserver"
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/erratic"
|
||||
"github.com/coredns/coredns/plugin/kubernetes"
|
||||
|
||||
"github.com/mholt/caddy"
|
||||
"github.com/miekg/dns"
|
||||
@@ -34,11 +32,10 @@ func setup(c *caddy.Controller) error {
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
if x, ok := m.(*kubernetes.Kubernetes); ok {
|
||||
ap.searchFunc = x.AutoPath
|
||||
}
|
||||
if x, ok := m.(*erratic.Erratic); ok {
|
||||
if x, ok := m.(AutoPather); ok {
|
||||
ap.searchFunc = x.AutoPath
|
||||
} else {
|
||||
return plugin.Error("autopath", fmt.Errorf("%s does not implement the AutoPather interface", mw))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -51,12 +48,6 @@ func setup(c *caddy.Controller) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// allowedPlugins has a list of plugin that can be used by autopath.
|
||||
var allowedPlugins = map[string]bool{
|
||||
"@kubernetes": true,
|
||||
"@erratic": true,
|
||||
}
|
||||
|
||||
func autoPathParse(c *caddy.Controller) (*AutoPath, string, error) {
|
||||
ap := &AutoPath{}
|
||||
mw := ""
|
||||
@@ -68,10 +59,7 @@ func autoPathParse(c *caddy.Controller) (*AutoPath, string, error) {
|
||||
}
|
||||
resolv := zoneAndresolv[len(zoneAndresolv)-1]
|
||||
if resolv[0] == '@' {
|
||||
_, ok := allowedPlugins[resolv]
|
||||
if ok {
|
||||
mw = resolv[1:]
|
||||
}
|
||||
mw = resolv[1:]
|
||||
} else {
|
||||
// assume file on disk
|
||||
rc, err := dns.ClientConfigFromFile(resolv)
|
||||
|
||||
@@ -18,10 +18,7 @@ supports health checks has a section "Health" in their README.
|
||||
|
||||
## Plugins
|
||||
|
||||
The following plugins report health to the health plugin:
|
||||
|
||||
* erratic
|
||||
* kubernetes
|
||||
Any plugin that implements the Healther interface will be used to report health.
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
@@ -36,9 +36,3 @@ func (h *health) poll() {
|
||||
}
|
||||
h.SetOk(true)
|
||||
}
|
||||
|
||||
// Plugins that implements the Healther interface.
|
||||
var healthers = map[string]bool{
|
||||
"erratic": true,
|
||||
"kubernetes": true,
|
||||
}
|
||||
|
||||
@@ -26,9 +26,9 @@ func setup(c *caddy.Controller) error {
|
||||
h := &health{Addr: addr}
|
||||
|
||||
c.OnStartup(func() error {
|
||||
for he := range healthers {
|
||||
m := dnsserver.GetConfig(c).Handler(he)
|
||||
if x, ok := m.(Healther); ok {
|
||||
plugins := dnsserver.GetConfig(c).Handlers()
|
||||
for _, p := range plugins {
|
||||
if x, ok := p.(Healther); ok {
|
||||
h.h = append(h.h, x)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user