middleware/kubernetes: fix aaaa response (#780)
* fix aaaa response * unit tests
This commit is contained in:
parent
81315b0b3b
commit
58006cf847
3 changed files with 25 additions and 8 deletions
|
@ -57,7 +57,7 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
|
||||||
path = strings.Join(dns.SplitDomainName(path)[1:], ".")
|
path = strings.Join(dns.SplitDomainName(path)[1:], ".")
|
||||||
newstate := state.NewWithQuestion(strings.Join([]string{name, path}, "."), state.QType())
|
newstate := state.NewWithQuestion(strings.Join([]string{name, path}, "."), state.QType())
|
||||||
records, extra, _, err = k.routeRequest(zone, newstate)
|
records, extra, _, err = k.routeRequest(zone, newstate)
|
||||||
if !k.IsNameError(err) {
|
if !k.IsNameError(err) && len(records) > 0 {
|
||||||
records = append(records, nil)
|
records = append(records, nil)
|
||||||
copy(records[1:], records)
|
copy(records[1:], records)
|
||||||
records[0] = newCNAME(origQName, records[0].Header().Name, records[0].Header().Ttl)
|
records[0] = newCNAME(origQName, records[0].Header().Name, records[0].Header().Ttl)
|
||||||
|
@ -79,7 +79,7 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
|
||||||
// Search . in this middleware
|
// Search . in this middleware
|
||||||
newstate := state.NewWithQuestion(strings.Join([]string{name, "."}, ""), state.QType())
|
newstate := state.NewWithQuestion(strings.Join([]string{name, "."}, ""), state.QType())
|
||||||
records, extra, _, err = k.routeRequest(zone, newstate)
|
records, extra, _, err = k.routeRequest(zone, newstate)
|
||||||
if !k.IsNameError(err) {
|
if !k.IsNameError(err) && len(records) > 0 {
|
||||||
records = append(records, nil)
|
records = append(records, nil)
|
||||||
copy(records[1:], records)
|
copy(records[1:], records)
|
||||||
records[0] = newCNAME(origQName, records[0].Header().Name, records[0].Header().Ttl)
|
records[0] = newCNAME(origQName, records[0].Header().Name, records[0].Header().Ttl)
|
||||||
|
|
|
@ -81,6 +81,22 @@ var dnsTestCases = map[string](*test.Case){
|
||||||
test.CNAME("svc0.testns.fed.svc.cluster.local. 0 IN CNAME svc0.testns.fed.svc.fd-az.fd-r.federal.test."),
|
test.CNAME("svc0.testns.fed.svc.cluster.local. 0 IN CNAME svc0.testns.fed.svc.fd-az.fd-r.federal.test."),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"AAAA Service (existing service)": {
|
||||||
|
Qname: "svc1.testns.svc.cluster.local.", Qtype: dns.TypeAAAA,
|
||||||
|
Rcode: dns.RcodeSuccess,
|
||||||
|
Answer: []dns.RR{},
|
||||||
|
Ns: []dns.RR{
|
||||||
|
test.SOA("cluster.local. 300 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"AAAA Service (non-existing service)": {
|
||||||
|
Qname: "svc0.testns.svc.cluster.local.", Qtype: dns.TypeAAAA,
|
||||||
|
Rcode: dns.RcodeNameError,
|
||||||
|
Answer: []dns.RR{},
|
||||||
|
Ns: []dns.RR{
|
||||||
|
test.SOA("cluster.local. 300 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var autopathCases = map[string](*test.Case){
|
var autopathCases = map[string](*test.Case){
|
||||||
|
|
|
@ -115,10 +115,7 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware.
|
||||||
return nil, nil, e
|
return nil, nil, e
|
||||||
}
|
}
|
||||||
switch state.Type() {
|
switch state.Type() {
|
||||||
case "AAAA":
|
case "A", "AAAA", "CNAME":
|
||||||
// AAAA not implemented
|
|
||||||
return nil, nil, errNoItems
|
|
||||||
case "A", "CNAME":
|
|
||||||
if state.Type() == "A" && isDefaultNS(state.Name(), r) {
|
if state.Type() == "A" && isDefaultNS(state.Name(), r) {
|
||||||
// If this is an A request for "ns.dns", respond with a "fake" record for coredns.
|
// If this is an A request for "ns.dns", respond with a "fake" record for coredns.
|
||||||
// SOA records always use this hardcoded name
|
// SOA records always use this hardcoded name
|
||||||
|
@ -126,6 +123,10 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware.
|
||||||
return svcs, nil, nil
|
return svcs, nil, nil
|
||||||
}
|
}
|
||||||
s, e := k.Entries(r)
|
s, e := k.Entries(r)
|
||||||
|
if state.QType() == dns.TypeAAAA {
|
||||||
|
// AAAA not implemented
|
||||||
|
return nil, nil, e
|
||||||
|
}
|
||||||
return s, nil, e // Haven't implemented debug queries yet.
|
return s, nil, e // Haven't implemented debug queries yet.
|
||||||
case "SRV":
|
case "SRV":
|
||||||
s, e := k.Entries(r)
|
s, e := k.Entries(r)
|
||||||
|
@ -325,8 +326,8 @@ func (k *Kubernetes) parseRequest(lowerCasedName string, qtype uint16) (r record
|
||||||
}
|
}
|
||||||
offset = 2
|
offset = 2
|
||||||
}
|
}
|
||||||
if qtype == dns.TypeA && len(segs) == 4 {
|
if (qtype == dns.TypeA || qtype == dns.TypeAAAA) && len(segs) == 4 {
|
||||||
// This is an endpoint A record request. Get first element as endpoint.
|
// This is an endpoint A/AAAA record request. Get first element as endpoint.
|
||||||
r.endpoint = segs[0]
|
r.endpoint = segs[0]
|
||||||
offset = 1
|
offset = 1
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue