diff --git a/plugin/kubernetes/handler_pod_insecure_test.go b/plugin/kubernetes/handler_pod_insecure_test.go index 276d4bbb3..6dcfd5629 100644 --- a/plugin/kubernetes/handler_pod_insecure_test.go +++ b/plugin/kubernetes/handler_pod_insecure_test.go @@ -25,6 +25,13 @@ var podModeInsecureCases = []test.Case{ test.A("172-0-0-2.podns.pod.cluster.local. 5 IN A 172.0.0.2"), }, }, + { + Qname: "blah.pod-nons.pod.cluster.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeNameError, + Ns: []dns.RR{ + test.SOA("cluster.local. 300 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1515173576 7200 1800 86400 30"), + }, + }, } func TestServeDNSModeInsecure(t *testing.T) { diff --git a/plugin/kubernetes/kubernetes.go b/plugin/kubernetes/kubernetes.go index 3a2c4870d..4e79738e7 100644 --- a/plugin/kubernetes/kubernetes.go +++ b/plugin/kubernetes/kubernetes.go @@ -311,6 +311,19 @@ func (k *Kubernetes) findPods(r recordRequest, zone string) (pods []msg.Service, zonePath := msg.Path(zone, "coredns") ip := "" + if strings.Count(podname, "-") == 3 && !strings.Contains(podname, "--") { + ip = strings.Replace(podname, "-", ".", -1) + } else { + ip = strings.Replace(podname, "-", ":", -1) + } + + if k.podMode == podModeInsecure { + if !wildcard(namespace) && !k.namespace(namespace) { // no wildcard, but namespace does not exist + return nil, errNoItems + } + return []msg.Service{{Key: strings.Join([]string{zonePath, Pod, namespace, podname}, "/"), Host: ip, TTL: k.ttl}}, err + } + err = errNoItems if wildcard(podname) && !wildcard(namespace) { // If namespace exist, err should be nil, so that we return nodata instead of NXDOMAIN @@ -319,22 +332,13 @@ func (k *Kubernetes) findPods(r recordRequest, zone string) (pods []msg.Service, } } - if strings.Count(podname, "-") == 3 && !strings.Contains(podname, "--") { - ip = strings.Replace(podname, "-", ".", -1) - } else { - ip = strings.Replace(podname, "-", ":", -1) - } - - if k.podMode == podModeInsecure { - return []msg.Service{{Key: strings.Join([]string{zonePath, Pod, namespace, podname}, "/"), Host: ip, TTL: k.ttl}}, nil - } - // PodModeVerified for _, p := range k.APIConn.PodIndex(ip) { // If namespace has a wildcard, filter results against Corefile namespace list. if wildcard(namespace) && !k.namespaceExposed(p.Namespace) { continue } + // check for matching ip and namespace if ip == p.Status.PodIP && match(namespace, p.Namespace) { s := msg.Service{Key: strings.Join([]string{zonePath, Pod, namespace, podname}, "/"), Host: ip, TTL: k.ttl}