middleware/kubernetes: autopath in sub package (#848)
Put the autopath stuff in a separate sub package. Tests are still included in the main kubernetes directory. Next steps (after this is merged), is pulling the autopath handling into the subpackage and fixing the tests.
This commit is contained in:
parent
050eccd69e
commit
760e667063
7 changed files with 103 additions and 95 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"github.com/coredns/coredns/core/dnsserver"
|
||||
"github.com/coredns/coredns/middleware"
|
||||
"github.com/coredns/coredns/middleware/kubernetes/autopath"
|
||||
"github.com/coredns/coredns/middleware/pkg/dnsutil"
|
||||
"github.com/coredns/coredns/middleware/proxy"
|
||||
"github.com/miekg/dns"
|
||||
|
@ -192,7 +193,7 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) {
|
|||
return nil, fmt.Errorf("incorrect number of arguments for federation, got %v, expected 2", len(args))
|
||||
case "autopath": // name zone
|
||||
args := c.RemainingArgs()
|
||||
k8s.AutoPath = AutoPath{
|
||||
k8s.autoPath = &autopath.AutoPath{
|
||||
NDots: defautNdots,
|
||||
HostSearchPath: []string{},
|
||||
ResolvConfFile: defaultResolvConfFile,
|
||||
|
@ -207,30 +208,29 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid NDOTS argument for autopath, got '%v', expected an integer", ndots)
|
||||
}
|
||||
k8s.AutoPath.NDots = ndots
|
||||
k8s.autoPath.NDots = ndots
|
||||
}
|
||||
if len(args) > 1 {
|
||||
switch args[1] {
|
||||
case dns.RcodeToString[dns.RcodeNameError]:
|
||||
k8s.AutoPath.OnNXDOMAIN = dns.RcodeNameError
|
||||
k8s.autoPath.OnNXDOMAIN = dns.RcodeNameError
|
||||
case dns.RcodeToString[dns.RcodeSuccess]:
|
||||
k8s.AutoPath.OnNXDOMAIN = dns.RcodeSuccess
|
||||
k8s.autoPath.OnNXDOMAIN = dns.RcodeSuccess
|
||||
case dns.RcodeToString[dns.RcodeServerFailure]:
|
||||
k8s.AutoPath.OnNXDOMAIN = dns.RcodeServerFailure
|
||||
k8s.autoPath.OnNXDOMAIN = dns.RcodeServerFailure
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid RESPONSE argument for autopath, got '%v', expected SERVFAIL, NOERROR, or NXDOMAIN", args[1])
|
||||
}
|
||||
}
|
||||
if len(args) > 2 {
|
||||
k8s.AutoPath.ResolvConfFile = args[2]
|
||||
k8s.autoPath.ResolvConfFile = args[2]
|
||||
}
|
||||
rc, err := dns.ClientConfigFromFile(k8s.AutoPath.ResolvConfFile)
|
||||
rc, err := dns.ClientConfigFromFile(k8s.autoPath.ResolvConfFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error when parsing %v: %v", k8s.AutoPath.ResolvConfFile, err)
|
||||
return nil, fmt.Errorf("error when parsing %v: %v", k8s.autoPath.ResolvConfFile, err)
|
||||
}
|
||||
k8s.AutoPath.HostSearchPath = rc.Search
|
||||
middleware.Zones(k8s.AutoPath.HostSearchPath).Normalize()
|
||||
k8s.AutoPath.Enabled = true
|
||||
k8s.autoPath.HostSearchPath = rc.Search
|
||||
middleware.Zones(k8s.autoPath.HostSearchPath).Normalize()
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue