diff options
author | 2022-03-07 12:18:23 -0500 | |
---|---|---|
committer | 2022-03-07 12:18:23 -0500 | |
commit | 3fe9d41a211055d748f4d98013aa86e7ffc1e63f (patch) | |
tree | f7803a4f0fc1a1257a0b72442e95059143c12b08 /plugin/kubernetes/ns.go | |
parent | 7263808fe1cfb3b9dfbc09d70c52d52a563e5254 (diff) | |
download | coredns-3fe9d41a211055d748f4d98013aa86e7ffc1e63f.tar.gz coredns-3fe9d41a211055d748f4d98013aa86e7ffc1e63f.tar.zst coredns-3fe9d41a211055d748f4d98013aa86e7ffc1e63f.zip |
plugin/k8s_external: fix external nsAddrs when CoreDNS Service has no External IPs (#4891)
fix external nsAddrs; add tests;
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Diffstat (limited to 'plugin/kubernetes/ns.go')
-rw-r--r-- | plugin/kubernetes/ns.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/plugin/kubernetes/ns.go b/plugin/kubernetes/ns.go index 84f4e344b..3e6a30586 100644 --- a/plugin/kubernetes/ns.go +++ b/plugin/kubernetes/ns.go @@ -15,8 +15,9 @@ func isDefaultNS(name, zone string) bool { // it returns a record for the local address of the machine we're running on. func (k *Kubernetes) nsAddrs(external bool, zone string) []dns.RR { var ( - svcNames []string - svcIPs []net.IP + svcNames []string + svcIPs []net.IP + foundEndpoint bool ) // Find the CoreDNS Endpoints @@ -25,6 +26,7 @@ func (k *Kubernetes) nsAddrs(external bool, zone string) []dns.RR { // Collect IPs for all Services of the Endpoints for _, endpoint := range endpoints { + foundEndpoint = true svcs := k.APIConn.SvcIndex(endpoint.Index) for _, svc := range svcs { if external { @@ -54,8 +56,8 @@ func (k *Kubernetes) nsAddrs(external bool, zone string) []dns.RR { } } - // If no local IPs matched any endpoints, use the localIPs directly - if len(svcIPs) == 0 { + // If no CoreDNS endpoints were found, use the localIPs directly + if !foundEndpoint { svcIPs = make([]net.IP, len(k.localIPs)) svcNames = make([]string, len(k.localIPs)) for i, localIP := range k.localIPs { |