plugin/k8s_extenral: Supports fallthrough option (#5959)

* Add fallthrough option to k8s_external plugin to allow transitioning control to the next plugin if the domain is not found
* Exit on start up if required plugin is not present.

Signed-off-by: vanceli <vanceli@tencent.com>

---------

Signed-off-by: vanceli <vanceli@tencent.com>
Co-authored-by: vanceli <vanceli@tencent.com>
This commit is contained in:
Vancl 2023-03-24 20:52:44 +08:00 committed by GitHub
parent 48c40ae1cd
commit 47dceabfc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 22 deletions

View file

@ -16,6 +16,7 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/etcd/msg"
"github.com/coredns/coredns/plugin/pkg/fall"
"github.com/coredns/coredns/plugin/pkg/upstream"
"github.com/coredns/coredns/request"
@ -39,6 +40,7 @@ type Externaler interface {
type External struct {
Next plugin.Handler
Zones []string
Fall fall.F
hostmaster string
apex string
@ -68,10 +70,6 @@ func (e *External) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
return plugin.NextOrFailure(e.Name(), e.Next, ctx, w, r)
}
if e.externalFunc == nil {
return plugin.NextOrFailure(e.Name(), e.Next, ctx, w, r)
}
state.Zone = zone
for _, z := range e.Zones {
// TODO(miek): save this in the External struct.
@ -93,6 +91,10 @@ func (e *External) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
m.Authoritative = true
if len(svc) == 0 {
if e.Fall.Through(state.Name()) && rcode == dns.RcodeNameError {
return plugin.NextOrFailure(e.Name(), e.Next, ctx, w, r)
}
m.Rcode = rcode
m.Ns = []dns.RR{e.soa(state)}
w.WriteMsg(m)