Add txt response per k8s spec

This commit is contained in:
Chris OHaver 2017-01-15 14:37:18 +00:00
parent 52e01264e8
commit 2d0b8293a4
2 changed files with 37 additions and 4 deletions

View file

@ -46,6 +46,7 @@ type Kubernetes struct {
const ( const (
PodModeDisabled = "disabled" // default. pod requests are ignored PodModeDisabled = "disabled" // default. pod requests are ignored
PodModeInsecure = "insecure" // ALL pod requests are answered without verfying they exist PodModeInsecure = "insecure" // ALL pod requests are answered without verfying they exist
DnsSchemaVersion = "1.0.0" // https://github.com/kubernetes/dns/blob/master/docs/specification.md
) )
type endpoint struct { type endpoint struct {
@ -82,8 +83,28 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware.
if e != nil { if e != nil {
return nil, nil, e return nil, nil, e
} }
switch state.Type() {
case "A", "SRV":
s, e := k.Records(r) s, e := k.Records(r)
return s, nil, e // Haven't implemented debug queries yet. return s, nil, e // Haven't implemented debug queries yet.
case "TXT":
s, e := k.recordsForTXT(r)
return s, nil, e
}
return nil, nil, nil
}
func (k *Kubernetes) recordsForTXT(r recordRequest) ([]msg.Service, error) {
switch r.typeName {
case "dns-version":
s := msg.Service{
Text: DnsSchemaVersion,
TTL: 28800,
Key: msg.Path(r.typeName+"."+r.zone, "coredns")}
return []msg.Service{s}, nil
}
return nil, nil
} }
// PrimaryZone will return the first non-reverse zone being handled by this middleware // PrimaryZone will return the first non-reverse zone being handled by this middleware
@ -253,6 +274,11 @@ func (k *Kubernetes) parseRequest(lowerCasedName, qtype string) (r recordRequest
return r, nil return r, nil
} }
if len(segs) == 1 && qtype == "TXT" {
r.typeName = segs[0]
return r, nil
}
return r, errors.New("invalid request") return r, errors.New("invalid request")
} }

View file

@ -218,6 +218,13 @@ var dnsTestCases = []test.Case{
test.PTR("115.0.0.10.in-addr.arpa. 303 IN PTR svc-c.test-1.svc.cluster.local."), test.PTR("115.0.0.10.in-addr.arpa. 303 IN PTR svc-c.test-1.svc.cluster.local."),
}, },
}, },
{
Qname: "dns-version.cluster.local.", Qtype: dns.TypeTXT,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.TXT("dns-version.cluster.local. 28800 IN TXT \"1.0.0\""),
},
},
} }
var dnsTestCasesPodsInsecure = []test.Case{ var dnsTestCasesPodsInsecure = []test.Case{