Add pkg/fall for Fallthrough (#1355)

* Add pkg/fall for Fallthrough

Move this into it's own package to facilitate tests. Important bug
was fixed: make the names fully qualified.

Add fall package to hosts, reverse, etcd, and fix kubernetes and any
tests. The k8s tests are still as-is, might need a future cleanup.
This commit is contained in:
Miek Gieben
2018-01-07 16:32:59 +00:00
committed by GitHub
parent 84ebbbc722
commit c6febe6250
22 changed files with 217 additions and 110 deletions

View File

@@ -59,7 +59,7 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
}
if k.IsNameError(err) {
if plugin.Fallthrough(k.Fallthrough, state.Name()) {
if k.Fall.Through(state.Name()) {
return plugin.NextOrFailure(k.Name(), k.Next, ctx, w, r)
}
return plugin.BackendError(&k, zone, dns.RcodeNameError, state, nil /* err */, plugin.Options{})

View File

@@ -12,6 +12,7 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/etcd/msg"
"github.com/coredns/coredns/plugin/pkg/dnsutil"
"github.com/coredns/coredns/plugin/pkg/fall"
"github.com/coredns/coredns/plugin/pkg/healthcheck"
"github.com/coredns/coredns/plugin/proxy"
"github.com/coredns/coredns/request"
@@ -40,7 +41,7 @@ type Kubernetes struct {
Namespaces map[string]bool
podMode string
endpointNameMode bool
Fallthrough *[]string // nil = disabled, empty = all zones, o/w zones
Fall *fall.F
ttl uint32
primaryZoneIndex int

View File

@@ -10,6 +10,7 @@ import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/dnsutil"
"github.com/coredns/coredns/plugin/pkg/fall"
"github.com/coredns/coredns/plugin/proxy"
"github.com/mholt/caddy"
@@ -172,8 +173,8 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, dnsControlOpts, error) {
}
return nil, opts, c.ArgErr()
case "fallthrough":
zones := c.RemainingArgs()
k8s.Fallthrough = &zones
k8s.Fall = fall.New()
k8s.Fall.SetZones(c.RemainingArgs())
case "upstream":
args := c.RemainingArgs()
if len(args) == 0 {

View File

@@ -347,7 +347,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeDisabled,
&[]string{"ip6.arpa", "inaddr.arpa", "foo.com"},
&[]string{"ip6.arpa.", "inaddr.arpa.", "foo.com."},
nil,
},
// Valid upstream
@@ -443,7 +443,7 @@ func TestKubernetesParse(t *testing.T) {
}
// fallthrough
foundFallthrough := k8sController.Fallthrough
foundFallthrough := k8sController.Fall
if foundFallthrough != nil {
failed := false
if test.expectedFallthrough == nil {