mirror of
https://github.com/coredns/coredns.git
synced 2025-12-17 07:45:13 -05:00
plugin/forward: configurable domain support for healthcheck (#5281)
* plugin/forward: configurable domain support for healthcheck Signed-off-by: hansedong <admin@yinxiaoluo.com>
This commit is contained in:
@@ -16,6 +16,8 @@ type HealthChecker interface {
|
||||
SetTLSConfig(*tls.Config)
|
||||
SetRecursionDesired(bool)
|
||||
GetRecursionDesired() bool
|
||||
SetDomain(domain string)
|
||||
GetDomain() string
|
||||
SetTCPTransport()
|
||||
}
|
||||
|
||||
@@ -23,6 +25,7 @@ type HealthChecker interface {
|
||||
type dnsHc struct {
|
||||
c *dns.Client
|
||||
recursionDesired bool
|
||||
domain string
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -31,7 +34,7 @@ var (
|
||||
)
|
||||
|
||||
// NewHealthChecker returns a new HealthChecker based on transport.
|
||||
func NewHealthChecker(trans string, recursionDesired bool) HealthChecker {
|
||||
func NewHealthChecker(trans string, recursionDesired bool, domain string) HealthChecker {
|
||||
switch trans {
|
||||
case transport.DNS, transport.TLS:
|
||||
c := new(dns.Client)
|
||||
@@ -39,7 +42,7 @@ func NewHealthChecker(trans string, recursionDesired bool) HealthChecker {
|
||||
c.ReadTimeout = hcReadTimeout
|
||||
c.WriteTimeout = hcWriteTimeout
|
||||
|
||||
return &dnsHc{c: c, recursionDesired: recursionDesired}
|
||||
return &dnsHc{c: c, recursionDesired: recursionDesired, domain: domain}
|
||||
}
|
||||
|
||||
log.Warningf("No healthchecker for transport %q", trans)
|
||||
@@ -58,6 +61,13 @@ func (h *dnsHc) GetRecursionDesired() bool {
|
||||
return h.recursionDesired
|
||||
}
|
||||
|
||||
func (h *dnsHc) SetDomain(domain string) {
|
||||
h.domain = domain
|
||||
}
|
||||
func (h *dnsHc) GetDomain() string {
|
||||
return h.domain
|
||||
}
|
||||
|
||||
func (h *dnsHc) SetTCPTransport() {
|
||||
h.c.Net = "tcp"
|
||||
}
|
||||
@@ -80,7 +90,7 @@ func (h *dnsHc) Check(p *Proxy) error {
|
||||
|
||||
func (h *dnsHc) send(addr string) error {
|
||||
ping := new(dns.Msg)
|
||||
ping.SetQuestion(".", dns.TypeNS)
|
||||
ping.SetQuestion(h.domain, dns.TypeNS)
|
||||
ping.MsgHdr.RecursionDesired = h.recursionDesired
|
||||
|
||||
m, _, err := h.c.Exchange(ping, addr)
|
||||
|
||||
Reference in New Issue
Block a user