aboutsummaryrefslogtreecommitdiff
path: root/plugin/kubernetes
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/kubernetes')
-rw-r--r--plugin/kubernetes/controller.go30
-rw-r--r--plugin/kubernetes/federation.go4
-rw-r--r--plugin/kubernetes/kubernetes.go18
3 files changed, 20 insertions, 32 deletions
diff --git a/plugin/kubernetes/controller.go b/plugin/kubernetes/controller.go
index 286f87d8e..db231c89d 100644
--- a/plugin/kubernetes/controller.go
+++ b/plugin/kubernetes/controller.go
@@ -72,7 +72,7 @@ type dnsControl struct {
svcLister cache.Indexer
podLister cache.Indexer
epLister cache.Indexer
- nsLister storeToNamespaceLister
+ nsLister cache.Store
// stopLock is used to enforce only a single call to Stop is active.
// Needed because we allow stopping through an http endpoint and
@@ -146,7 +146,7 @@ func newdnsController(kubeClient *kubernetes.Clientset, opts dnsControlOpts) *dn
cache.Indexers{epNameNamespaceIndex: epNameNamespaceIndexFunc, epIPIndex: epIPIndexFunc})
}
- dns.nsLister.Store, dns.nsController = cache.NewInformer(
+ dns.nsLister, dns.nsController = cache.NewInformer(
&cache.ListWatch{
ListFunc: namespaceListFunc(dns.client, dns.selector),
WatchFunc: namespaceWatchFunc(dns.client, dns.selector),
@@ -156,11 +156,6 @@ func newdnsController(kubeClient *kubernetes.Clientset, opts dnsControlOpts) *dn
return &dns
}
-// storeToNamespaceLister makes a Store that lists Namespaces.
-type storeToNamespaceLister struct {
- cache.Store
-}
-
func podIPIndexFunc(obj interface{}) ([]string, error) {
p, ok := obj.(*api.Pod)
if !ok {
@@ -311,9 +306,8 @@ func namespaceWatchFunc(c *kubernetes.Clientset, s labels.Selector) func(options
}
}
-func (dns *dnsControl) SetWatchChan(c dnswatch.Chan) {
- dns.watchChan = c
-}
+func (dns *dnsControl) SetWatchChan(c dnswatch.Chan) { dns.watchChan = c }
+func (dns *dnsControl) StopWatching(qname string) { delete(dns.watched, qname) }
func (dns *dnsControl) Watch(qname string) error {
if dns.watchChan == nil {
@@ -323,10 +317,6 @@ func (dns *dnsControl) Watch(qname string) error {
return nil
}
-func (dns *dnsControl) StopWatching(qname string) {
- delete(dns.watched, qname)
-}
-
// Stop stops the controller.
func (dns *dnsControl) Stop() error {
dns.stopLock.Lock()
@@ -621,15 +611,9 @@ func (dns *dnsControl) sendUpdates(oldObj, newObj interface{}) {
}
}
-func (dns *dnsControl) Add(obj interface{}) {
- dns.sendUpdates(nil, obj)
-}
-func (dns *dnsControl) Delete(obj interface{}) {
- dns.sendUpdates(obj, nil)
-}
-func (dns *dnsControl) Update(oldObj, newObj interface{}) {
- dns.sendUpdates(oldObj, newObj)
-}
+func (dns *dnsControl) Add(obj interface{}) { dns.sendUpdates(nil, obj) }
+func (dns *dnsControl) Delete(obj interface{}) { dns.sendUpdates(obj, nil) }
+func (dns *dnsControl) Update(oldObj, newObj interface{}) { dns.sendUpdates(oldObj, newObj) }
// subsetsEquivalent checks if two endpoint subsets are significantly equivalent
// I.e. that they have the same ready addresses, host names, ports (including protocol
diff --git a/plugin/kubernetes/federation.go b/plugin/kubernetes/federation.go
index 78e31668b..bf169b911 100644
--- a/plugin/kubernetes/federation.go
+++ b/plugin/kubernetes/federation.go
@@ -44,8 +44,8 @@ func (k *Kubernetes) Federations(state request.Request, fname, fzone string) (ms
}
if r.endpoint == "" {
- return msg.Service{Host: dnsutil.Join([]string{r.service, r.namespace, fname, r.podOrSvc, lz, lr, fzone})}, nil
+ return msg.Service{Host: dnsutil.Join(r.service, r.namespace, fname, r.podOrSvc, lz, lr, fzone)}, nil
}
- return msg.Service{Host: dnsutil.Join([]string{r.endpoint, r.service, r.namespace, fname, r.podOrSvc, lz, lr, fzone})}, nil
+ return msg.Service{Host: dnsutil.Join(r.endpoint, r.service, r.namespace, fname, r.podOrSvc, lz, lr, fzone)}, nil
}
diff --git a/plugin/kubernetes/kubernetes.go b/plugin/kubernetes/kubernetes.go
index 4bdcd4877..9eac7d467 100644
--- a/plugin/kubernetes/kubernetes.go
+++ b/plugin/kubernetes/kubernetes.go
@@ -296,14 +296,18 @@ func (k *Kubernetes) Records(state request.Request, exact bool) ([]msg.Service,
// serviceFQDN returns the k8s cluster dns spec service FQDN for the service (or endpoint) object.
func serviceFQDN(obj meta.Object, zone string) string {
- return dnsutil.Join(append([]string{}, obj.GetName(), obj.GetNamespace(), Svc, zone))
+ return dnsutil.Join(obj.GetName(), obj.GetNamespace(), Svc, zone)
}
// podFQDN returns the k8s cluster dns spec FQDN for the pod.
func podFQDN(p *api.Pod, zone string) string {
- name := strings.Replace(p.Status.PodIP, ".", "-", -1)
- name = strings.Replace(name, ":", "-", -1)
- return dnsutil.Join(append([]string{}, name, p.GetNamespace(), Pod, zone))
+ if strings.Contains(p.Status.PodIP, ".") {
+ name := strings.Replace(p.Status.PodIP, ".", "-", -1)
+ return dnsutil.Join(name, p.GetNamespace(), Pod, zone)
+ }
+
+ name := strings.Replace(p.Status.PodIP, ":", "-", -1)
+ return dnsutil.Join(name, p.GetNamespace(), Pod, zone)
}
// endpointFQDN returns a list of k8s cluster dns spec service FQDNs for each subset in the endpoint.
@@ -311,7 +315,7 @@ func endpointFQDN(ep *api.Endpoints, zone string, endpointNameMode bool) []strin
var names []string
for _, ss := range ep.Subsets {
for _, addr := range ss.Addresses {
- names = append(names, dnsutil.Join(append([]string{}, endpointHostname(addr, endpointNameMode), serviceFQDN(ep, zone))))
+ names = append(names, dnsutil.Join(endpointHostname(addr, endpointNameMode), serviceFQDN(ep, zone)))
}
}
return names
@@ -319,7 +323,7 @@ func endpointFQDN(ep *api.Endpoints, zone string, endpointNameMode bool) []strin
func endpointHostname(addr api.EndpointAddress, endpointNameMode bool) string {
if addr.Hostname != "" {
- return strings.ToLower(addr.Hostname)
+ return addr.Hostname
}
if endpointNameMode && addr.TargetRef != nil && addr.TargetRef.Name != "" {
return addr.TargetRef.Name
@@ -328,7 +332,7 @@ func endpointHostname(addr api.EndpointAddress, endpointNameMode bool) string {
return strings.Replace(addr.IP, ".", "-", -1)
}
if strings.Contains(addr.IP, ":") {
- return strings.ToLower(strings.Replace(addr.IP, ":", "-", -1))
+ return strings.Replace(addr.IP, ":", "-", -1)
}
return ""
}