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

@ -1,6 +1,7 @@
package external
import (
"errors"
"strconv"
"github.com/coredns/caddy"
@ -9,7 +10,9 @@ import (
"github.com/coredns/coredns/plugin/pkg/upstream"
)
func init() { plugin.Register("k8s_external", setup) }
const pluginName = "k8s_external"
func init() { plugin.Register(pluginName, setup) }
func setup(c *caddy.Controller) error {
e, err := parse(c)
@ -21,14 +24,18 @@ func setup(c *caddy.Controller) error {
c.OnStartup(func() error {
m := dnsserver.GetConfig(c).Handler("kubernetes")
if m == nil {
return nil
return plugin.Error(pluginName, errors.New("kubernetes plugin not loaded"))
}
if x, ok := m.(Externaler); ok {
e.externalFunc = x.External
e.externalAddrFunc = x.ExternalAddress
e.externalServicesFunc = x.ExternalServices
e.externalSerialFunc = x.ExternalSerial
x, ok := m.(Externaler)
if !ok {
return plugin.Error(pluginName, errors.New("kubernetes plugin does not implement the Externaler interface"))
}
e.externalFunc = x.External
e.externalAddrFunc = x.ExternalAddress
e.externalServicesFunc = x.ExternalServices
e.externalSerialFunc = x.ExternalSerial
return nil
})
@ -70,6 +77,8 @@ func parse(c *caddy.Controller) (*External, error) {
e.apex = args[0]
case "headless":
e.headless = true
case "fallthrough":
e.Fall.SetZonesFromArgs(c.RemainingArgs())
default:
return nil, c.Errf("unknown property '%s'", c.Val())
}