plugin/kubernetes: check for bare zone query (#1692)
* check for bare zone query * check for bare type query
This commit is contained in:
parent
9a7e487a5a
commit
51e1442bd9
5 changed files with 49 additions and 1 deletions
|
@ -231,6 +231,20 @@ var dnsTestCases = []test.Case{
|
||||||
test.AAAA("5678-abcd--1.hdls1.testns.svc.cluster.local. 5 IN AAAA 5678:abcd::1"),
|
test.AAAA("5678-abcd--1.hdls1.testns.svc.cluster.local. 5 IN AAAA 5678:abcd::1"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Qname: "svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
|
Rcode: dns.RcodeSuccess,
|
||||||
|
Ns: []dns.RR{
|
||||||
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Qname: "pod.cluster.local.", Qtype: dns.TypeA,
|
||||||
|
Rcode: dns.RcodeSuccess,
|
||||||
|
Ns: []dns.RR{
|
||||||
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServeDNS(t *testing.T) {
|
func TestServeDNS(t *testing.T) {
|
||||||
|
|
|
@ -273,6 +273,9 @@ func (k *Kubernetes) Records(state request.Request, exact bool) ([]msg.Service,
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
|
if r.podOrSvc == "" {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
if dnsutil.IsReverse(state.Name()) > 0 {
|
if dnsutil.IsReverse(state.Name()) > 0 {
|
||||||
return nil, errNoItems
|
return nil, errNoItems
|
||||||
|
|
|
@ -35,6 +35,27 @@ var kubeApexCases = []test.Case{
|
||||||
test.A("ns.dns.cluster.local. 303 IN A 127.0.0.1"),
|
test.A("ns.dns.cluster.local. 303 IN A 127.0.0.1"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Qname: "cluster.local.", Qtype: dns.TypeA,
|
||||||
|
Rcode: dns.RcodeSuccess,
|
||||||
|
Ns: []dns.RR{
|
||||||
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Qname: "cluster.local.", Qtype: dns.TypeAAAA,
|
||||||
|
Rcode: dns.RcodeSuccess,
|
||||||
|
Ns: []dns.RR{
|
||||||
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Qname: "cluster.local.", Qtype: dns.TypeSRV,
|
||||||
|
Rcode: dns.RcodeSuccess,
|
||||||
|
Ns: []dns.RR{
|
||||||
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServeDNSApex(t *testing.T) {
|
func TestServeDNSApex(t *testing.T) {
|
||||||
|
|
|
@ -35,6 +35,10 @@ func parseRequest(state request.Request) (r recordRequest, err error) {
|
||||||
// Federations are handled in the federation plugin. And aren't parsed here.
|
// Federations are handled in the federation plugin. And aren't parsed here.
|
||||||
|
|
||||||
base, _ := dnsutil.TrimZone(state.Name(), state.Zone)
|
base, _ := dnsutil.TrimZone(state.Name(), state.Zone)
|
||||||
|
// return NODATA for apex queries
|
||||||
|
if base == "" || base == Svc || base == Pod {
|
||||||
|
return r, nil
|
||||||
|
}
|
||||||
segs := dns.SplitDomainName(base)
|
segs := dns.SplitDomainName(base)
|
||||||
|
|
||||||
r.port = "*"
|
r.port = "*"
|
||||||
|
|
|
@ -19,6 +19,12 @@ func TestParseRequest(t *testing.T) {
|
||||||
{"*.any.*.any.svc.inter.webs.test.", "*.any..*.any.svc"},
|
{"*.any.*.any.svc.inter.webs.test.", "*.any..*.any.svc"},
|
||||||
// A request of endpoint
|
// A request of endpoint
|
||||||
{"1-2-3-4.webs.mynamespace.svc.inter.webs.test.", "*.*.1-2-3-4.webs.mynamespace.svc"},
|
{"1-2-3-4.webs.mynamespace.svc.inter.webs.test.", "*.*.1-2-3-4.webs.mynamespace.svc"},
|
||||||
|
// bare zone
|
||||||
|
{"inter.webs.test.", "....."},
|
||||||
|
// bare svc type
|
||||||
|
{"svc.inter.webs.test.", "....."},
|
||||||
|
// bare pod type
|
||||||
|
{"pod.inter.webs.test.", "....."},
|
||||||
}
|
}
|
||||||
for i, tc := range tests {
|
for i, tc := range tests {
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
|
@ -53,4 +59,4 @@ func TestParseInvalidRequest(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const zone = "intern.webs.tests."
|
const zone = "inter.webs.tests."
|
||||||
|
|
Loading…
Add table
Reference in a new issue