aboutsummaryrefslogtreecommitdiff
path: root/plugin/kubernetes/xfr.go
diff options
context:
space:
mode:
authorGravatar Chris O'Haver <cohaver@infoblox.com> 2018-10-10 15:28:45 -0400
committerGravatar John Belamaric <jbelamaric@google.com> 2018-10-10 12:28:45 -0700
commit974ed086f25ad45a01947e276e2eb8aa73d007a3 (patch)
tree2c1468f5a4e90634382a81904ef2736ca44198a7 /plugin/kubernetes/xfr.go
parent8432f1420732e61cb1a7ebb9d6446db6f43aa850 (diff)
downloadcoredns-974ed086f25ad45a01947e276e2eb8aa73d007a3.tar.gz
coredns-974ed086f25ad45a01947e276e2eb8aa73d007a3.tar.zst
coredns-974ed086f25ad45a01947e276e2eb8aa73d007a3.zip
use keys (#2167)
Diffstat (limited to 'plugin/kubernetes/xfr.go')
-rw-r--r--plugin/kubernetes/xfr.go58
1 files changed, 28 insertions, 30 deletions
diff --git a/plugin/kubernetes/xfr.go b/plugin/kubernetes/xfr.go
index eaf554c6a..b76e1def9 100644
--- a/plugin/kubernetes/xfr.go
+++ b/plugin/kubernetes/xfr.go
@@ -9,6 +9,7 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/etcd/msg"
"github.com/coredns/coredns/request"
+ "k8s.io/client-go/tools/cache"
"github.com/miekg/dns"
api "k8s.io/api/core/v1"
@@ -114,39 +115,36 @@ func (k *Kubernetes) transfer(c chan dns.RR, zone string) {
continue
}
- endpointsList := k.APIConn.EpIndex(svc.Name + "." + svc.Namespace)
+ key, err := cache.MetaNamespaceKeyFunc(svc)
+ if err != nil {
+ return
+ }
+ ep := k.APIConn.EpIndex(key)
+ for _, eps := range ep.Subsets {
+ srvWeight := calcSRVWeight(len(eps.Addresses))
+ for _, addr := range eps.Addresses {
+ s := msg.Service{Host: addr.IP, TTL: k.ttl}
+ s.Key = strings.Join(svcBase, "/")
+ // We don't need to change the msg.Service host from IP to Name yet
+ // so disregard the return value here
+ emitAddressRecord(c, s)
- for _, ep := range endpointsList {
- if ep.Name != svc.Name || ep.Namespace != svc.Namespace {
- continue
- }
+ s.Key = strings.Join(append(svcBase, endpointHostname(addr, k.endpointNameMode)), "/")
+ // Change host from IP to Name for SRV records
+ host := emitAddressRecord(c, s)
+ s.Host = host
- for _, eps := range ep.Subsets {
- srvWeight := calcSRVWeight(len(eps.Addresses))
- for _, addr := range eps.Addresses {
- s := msg.Service{Host: addr.IP, TTL: k.ttl}
- s.Key = strings.Join(svcBase, "/")
- // We don't need to change the msg.Service host from IP to Name yet
- // so disregard the return value here
- emitAddressRecord(c, s)
-
- s.Key = strings.Join(append(svcBase, endpointHostname(addr, k.endpointNameMode)), "/")
- // Change host from IP to Name for SRV records
- host := emitAddressRecord(c, s)
- s.Host = host
-
- for _, p := range eps.Ports {
- // As per spec unnamed ports do not have a srv record
- // https://github.com/kubernetes/dns/blob/master/docs/specification.md#232---srv-records
- if p.Name == "" {
- continue
- }
-
- s.Port = int(p.Port)
-
- s.Key = strings.Join(append(svcBase, strings.ToLower("_"+string(p.Protocol)), strings.ToLower("_"+string(p.Name))), "/")
- c <- s.NewSRV(msg.Domain(s.Key), srvWeight)
+ for _, p := range eps.Ports {
+ // As per spec unnamed ports do not have a srv record
+ // https://github.com/kubernetes/dns/blob/master/docs/specification.md#232---srv-records
+ if p.Name == "" {
+ continue
}
+
+ s.Port = int(p.Port)
+
+ s.Key = strings.Join(append(svcBase, strings.ToLower("_"+string(p.Protocol)), strings.ToLower("_"+string(p.Name))), "/")
+ c <- s.NewSRV(msg.Domain(s.Key), srvWeight)
}
}
}