coredns/middleware/kubernetes/federation.go
Miek Gieben aacb91ef0b mw/kubernetes: remove kService and kPod
Remove the intermediate step of gathering everyhing in a kPod and
kService and extracting the msg.Service from there. Now findPods and
findServices return []msg.Service.

This cuts down on the code and also removed the double looping of
finding the data we need, so it should be faster.
2017-08-22 09:25:58 +01:00

43 lines
1.3 KiB
Go

package kubernetes
import (
"strings"
"github.com/coredns/coredns/middleware/etcd/msg"
"github.com/coredns/coredns/request"
)
// The federation node.Labels keys used.
const (
// TODO: Do not hardcode these labels. Pull them out of the API instead.
//
// We can get them via ....
// import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// metav1.LabelZoneFailureDomain
// metav1.LabelZoneRegion
//
// But importing above breaks coredns with flag collision of 'log_dir'
LabelZone = "failure-domain.beta.kubernetes.io/zone"
LabelRegion = "failure-domain.beta.kubernetes.io/region"
)
// Federations is used from the federations middleware to return the service that should be
// returned as a CNAME for federation(s) to work.
func (k *Kubernetes) Federations(state request.Request, fname, fzone string) (msg.Service, error) {
nodeName := k.localNodeName()
node, err := k.APIConn.GetNodeByName(nodeName)
if err != nil {
return msg.Service{}, err
}
r, err := parseRequest(state)
lz := node.Labels[LabelZone]
lr := node.Labels[LabelRegion]
if r.endpoint == "" {
return msg.Service{Host: strings.Join([]string{r.service, r.namespace, fname, r.podOrSvc, lz, lr, fzone}, ".")}, nil
}
return msg.Service{Host: strings.Join([]string{r.endpoint, r.service, r.namespace, fname, r.podOrSvc, lz, lr, fzone}, ".")}, nil
}