From 378806eb44faa33f9d1abe9efd7d3dfcb8824d96 Mon Sep 17 00:00:00 2001 From: Esonhugh Date: Sun, 21 Jul 2024 02:11:50 +0800 Subject: [PATCH] update: dns check for ns.dns.cluster.local ip looking up --- pkg/utils.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/utils.go b/pkg/utils.go index 9cbcc85..6decd3a 100644 --- a/pkg/utils.go +++ b/pkg/utils.go @@ -43,7 +43,7 @@ func CheckKubeDNS(dns ...*SpiderResolver) bool { if len(dns) > 0 { // use custom dns rs = dns[0] } - if CheckKubeDNS_DefaultAPIServer(rs) || CheckKubeDNS_DNSVersion(rs) { + if CheckKubeDNS_DefaultAPIServer(rs) || CheckKubeDNS_DNSVersion(rs) || CheckKubeDNS_NS_DNS_DOMAIN(rs) { return true } } @@ -81,3 +81,19 @@ func CheckKubeDNS_DNSVersion(dns *SpiderResolver) bool { log.Tracef("dns-version not found in dns(%v)", dns.CurrentDNS()) return false } + +func CheckKubeDNS_NS_DNS_DOMAIN(dns *SpiderResolver) bool { + info, err := dns.ARecord("ns.dns." + Zone) + if err == nil { + log.Infof("ns.dns.%v found in dns(%v)! response: %v", Zone, dns.CurrentDNS(), info) + return true + } + log.Tracef("ns.dns.%v not found in dns(%v)", Zone, dns.CurrentDNS()) + info, err = dns.ARecord("ns.dns") // try shorted if Zone is incorrect + if err == nil { + log.Warnf("ns.dns found in dns(%v)! response: %v, maybe %v is incorrect", dns.CurrentDNS(), info, Zone) + return true + } + log.Tracef("ns.dns not found in dns(%v)", dns.CurrentDNS()) + return false +}