diff options
Diffstat (limited to 'middleware/kubernetes/kubernetes.go')
-rw-r--r-- | middleware/kubernetes/kubernetes.go | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/middleware/kubernetes/kubernetes.go b/middleware/kubernetes/kubernetes.go index e4323c3b7..5e93420e9 100644 --- a/middleware/kubernetes/kubernetes.go +++ b/middleware/kubernetes/kubernetes.go @@ -55,7 +55,7 @@ const ( // PodModeInsecure is where pod requests are answered without verfying they exist PodModeInsecure = "insecure" // DNSSchemaVersion is the schema version: https://github.com/kubernetes/dns/blob/master/docs/specification.md - DNSSchemaVersion = "1.0.0" + DNSSchemaVersion = "1.0.1" ) type endpoint struct { @@ -97,7 +97,7 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware. } switch state.Type() { - case "A", "SRV": + case "A", "CNAME": if state.Type() == "A" && isDefaultNS(state.Name(), r) { // If this is an A request for "ns.dns", respond with a "fake" record for coredns. // SOA records always use this hardcoded name @@ -106,6 +106,16 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware. } s, e := k.Records(r) return s, nil, e // Haven't implemented debug queries yet. + case "SRV": + s, e := k.Records(r) + // SRV for external services is not yet implemented, so remove those records + noext := []msg.Service{} + for _, svc := range s { + if t, _ := svc.HostType(); t != dns.TypeCNAME { + noext = append(noext, svc) + } + } + return noext, nil, e case "TXT": err := k.recordsForTXT(r, &svcs) return svcs, nil, err @@ -373,6 +383,14 @@ func (k *Kubernetes) getRecordsForK8sItems(services []service, pods []pod, zone Port: int(p.Port)} records = append(records, s) } + // If the addr is not an IP (i.e. an external service), add the record ... + s := msg.Service{ + Key: strings.Join([]string{zonePath, "svc", svc.namespace, svc.name}, "/"), + Host: svc.addr} + if t, _ := s.HostType(); t == dns.TypeCNAME { + records = append(records, s) + } + } } @@ -466,8 +484,16 @@ func (k *Kubernetes) findServices(r recordRequest) ([]service, error) { if nsWildcard && (len(k.Namespaces) > 0) && (!dnsstrings.StringInSlice(svc.Namespace, k.Namespaces)) { continue } - s := service{name: svc.Name, namespace: svc.Namespace, addr: svc.Spec.ClusterIP} - if s.addr != api.ClusterIPNone { + s := service{name: svc.Name, namespace: svc.Namespace} + // External Service + if svc.Spec.ExternalName != "" { + s.addr = svc.Spec.ExternalName + resultItems = append(resultItems, s) + continue + } + // ClusterIP service + if svc.Spec.ClusterIP != api.ClusterIPNone { + s.addr = svc.Spec.ClusterIP for _, p := range svc.Spec.Ports { if !(symbolMatches(r.port, strings.ToLower(p.Name), portWildcard) && symbolMatches(r.protocol, strings.ToLower(string(p.Protocol)), protocolWildcard)) { continue @@ -478,6 +504,7 @@ func (k *Kubernetes) findServices(r recordRequest) ([]service, error) { continue } // Headless service + s.addr = svc.Spec.ClusterIP endpointsList := k.APIConn.EndpointsList() for _, ep := range endpointsList.Items { |