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

@ -4,24 +4,33 @@ import (
"testing"
"github.com/coredns/caddy"
"github.com/coredns/coredns/plugin/pkg/fall"
)
func TestSetup(t *testing.T) {
tests := []struct {
input string
shouldErr bool
expectedZone string
expectedApex string
expectedHeadless bool
input string
shouldErr bool
expectedZone string
expectedApex string
expectedHeadless bool
expectedFallthrough fall.F
}{
{`k8s_external`, false, "", "dns", false},
{`k8s_external example.org`, false, "example.org.", "dns", false},
{`k8s_external`, false, "", "dns", false, fall.Zero},
{`k8s_external example.org`, false, "example.org.", "dns", false, fall.Zero},
{`k8s_external example.org {
apex testdns
}`, false, "example.org.", "testdns", false},
}`, false, "example.org.", "testdns", false, fall.Zero},
{`k8s_external example.org {
headless
}`, false, "example.org.", "dns", true},
}`, false, "example.org.", "dns", true, fall.Zero},
{`k8s_external example.org {
fallthrough
}`, false, "example.org.", "dns", false, fall.Root},
{`k8s_external example.org {
fallthrough ip6.arpa inaddr.arpa foo.com
}`, false, "example.org.", "dns", false,
fall.F{Zones: []string{"ip6.arpa.", "inaddr.arpa.", "foo.com."}}},
}
for i, test := range tests {
@ -53,5 +62,10 @@ func TestSetup(t *testing.T) {
t.Errorf("Test %d, expected headless %q for input %s, got: %v", i, test.expectedApex, test.input, e.headless)
}
}
if !test.shouldErr {
if !e.Fall.Equal(test.expectedFallthrough) {
t.Errorf("Test %d, expected to be initialized with fallthrough %q for input %s, got: %v", i, test.expectedFallthrough, test.input, e.Fall)
}
}
}
}