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
This commit is contained in:
Chris O'Haver 2019-09-05 09:07:55 -04:00 committed by GitHub
parent d79562842a
commit 630d3d60b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 91 additions and 51 deletions

View file

@ -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))