aboutsummaryrefslogtreecommitdiff
path: root/plugin/kubernetes/ns.go
diff options
context:
space:
mode:
authorGravatar Chris O'Haver <cohaver@infoblox.com> 2019-09-05 09:07:55 -0400
committerGravatar GitHub <noreply@github.com> 2019-09-05 09:07:55 -0400
commit630d3d60b9fa3b9c1f070e4aa0504e50a85d70c2 (patch)
treeb9b95d55ecca3964142f6d064b48065f1cb5128b /plugin/kubernetes/ns.go
parentd79562842aacfa5808ec0b8d160d720470ece060 (diff)
downloadcoredns-630d3d60b9fa3b9c1f070e4aa0504e50a85d70c2.tar.gz
coredns-630d3d60b9fa3b9c1f070e4aa0504e50a85d70c2.tar.zst
coredns-630d3d60b9fa3b9c1f070e4aa0504e50a85d70c2.zip
plugin/kubernetes: Handle multiple local IPs and bind (#3208)
* use all local IPs * mult/bind ips * gofmt + boundIPs fix * fix no matching endpoint case * don't duplicate NS records in answer * fix answer dedup * fix comment * add multi local ip test case
Diffstat (limited to 'plugin/kubernetes/ns.go')
-rw-r--r--plugin/kubernetes/ns.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/plugin/kubernetes/ns.go b/plugin/kubernetes/ns.go
index 4774e176f..f21890cc9 100644
--- a/plugin/kubernetes/ns.go
+++ b/plugin/kubernetes/ns.go
@@ -21,15 +21,10 @@ func (k *Kubernetes) nsAddrs(external bool, zone string) []dns.RR {
svcIPs []net.IP
)
- // Find the CoreDNS Endpoint
- localIP := k.interfaceAddrsFunc()
- endpoints := k.APIConn.EpIndexReverse(localIP.String())
+ // Find the CoreDNS Endpoints
+ for _, localIP := range k.localIPs {
+ endpoints := k.APIConn.EpIndexReverse(localIP.String())
- // If the CoreDNS Endpoint is not found, use the locally bound IP address
- if len(endpoints) == 0 {
- svcNames = []string{defaultNSName + zone}
- svcIPs = []net.IP{localIP}
- } else {
// Collect IPs for all Services of the Endpoints
for _, endpoint := range endpoints {
svcs := k.APIConn.SvcIndex(object.ServiceKey(endpoint.Name, endpoint.Namespace))
@@ -59,6 +54,16 @@ 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 {
+ svcIPs = make([]net.IP, len(k.localIPs))
+ svcNames = make([]string, len(k.localIPs))
+ for i, localIP := range k.localIPs {
+ svcNames[i] = defaultNSName + zone
+ svcIPs[i] = localIP
+ }
+ }
+
// Create an RR slice of collected IPs
var rrs []dns.RR
rrs = make([]dns.RR, len(svcIPs))