aboutsummaryrefslogtreecommitdiff
path: root/middleware/kubernetes/kubernetes.go
diff options
context:
space:
mode:
authorGravatar Markus Sommer <markus@splork.de> 2017-08-04 15:41:55 +0200
committerGravatar John Belamaric <jbelamaric@infoblox.com> 2017-08-04 09:41:55 -0400
commitd0d7f4c89abebcfb5783fcf1ea4fe1a2090e9f11 (patch)
tree8ff7da72af232e139d3892cf38315c2184402fa2 /middleware/kubernetes/kubernetes.go
parent2c0fc3182caa2d76a2c83a2a3b85ec5c5fa8f915 (diff)
downloadcoredns-d0d7f4c89abebcfb5783fcf1ea4fe1a2090e9f11.tar.gz
coredns-d0d7f4c89abebcfb5783fcf1ea4fe1a2090e9f11.tar.zst
coredns-d0d7f4c89abebcfb5783fcf1ea4fe1a2090e9f11.zip
Kubernetes srv (#823)
* Treat absence of port/service in SRV as wildcard Normally, a SRV-request should have the form _<service>._<port>.<name>.<zone>. The k8s peer-finder which is used for bootstrapping by some applications will however query for SRV at <name>.<zone>. To compensate for this behaviour, treat the absence of _<service> and _<port> as wildcards. * Modified tests with new SRV behaviour Added a testcase for a SRV request without port & service Removed now valid query from invalidSRVQueries * Forgot to run gofmt on test/kubernetes_test.go
Diffstat (limited to 'middleware/kubernetes/kubernetes.go')
-rw-r--r--middleware/kubernetes/kubernetes.go50
1 files changed, 29 insertions, 21 deletions
diff --git a/middleware/kubernetes/kubernetes.go b/middleware/kubernetes/kubernetes.go
index 8a87322e8..7d824f890 100644
--- a/middleware/kubernetes/kubernetes.go
+++ b/middleware/kubernetes/kubernetes.go
@@ -299,34 +299,42 @@ func (k *Kubernetes) parseRequest(lowerCasedName string, qtype uint16) (r record
offset := 0
if qtype == dns.TypeSRV {
- if len(segs) != 5 {
- return r, errInvalidRequest
- }
- // This is a SRV style request, get first two elements as port and
- // protocol, stripping leading underscores if present.
- if segs[0][0] == '_' {
- r.port = segs[0][1:]
+ // The kubernetes peer-finder expects queries with empty port and service to resolve
+ // If neither is specified, treat it as a wildcard
+ if len(segs) == 3 {
+ r.port = "*"
+ r.service = "*"
+ offset = 0
} else {
- r.port = segs[0]
- if !symbolContainsWildcard(r.port) {
+ if len(segs) != 5 {
return r, errInvalidRequest
}
- }
- if segs[1][0] == '_' {
- r.protocol = segs[1][1:]
- if r.protocol != "tcp" && r.protocol != "udp" {
- return r, errInvalidRequest
+ // This is a SRV style request, get first two elements as port and
+ // protocol, stripping leading underscores if present.
+ if segs[0][0] == '_' {
+ r.port = segs[0][1:]
+ } else {
+ r.port = segs[0]
+ if !symbolContainsWildcard(r.port) {
+ return r, errInvalidRequest
+ }
}
- } else {
- r.protocol = segs[1]
- if !symbolContainsWildcard(r.protocol) {
+ if segs[1][0] == '_' {
+ r.protocol = segs[1][1:]
+ if r.protocol != "tcp" && r.protocol != "udp" {
+ return r, errInvalidRequest
+ }
+ } else {
+ r.protocol = segs[1]
+ if !symbolContainsWildcard(r.protocol) {
+ return r, errInvalidRequest
+ }
+ }
+ if r.port == "" || r.protocol == "" {
return r, errInvalidRequest
}
+ offset = 2
}
- if r.port == "" || r.protocol == "" {
- return r, errInvalidRequest
- }
- offset = 2
}
if (qtype == dns.TypeA || qtype == dns.TypeAAAA) && len(segs) == 4 {
// This is an endpoint A/AAAA record request. Get first element as endpoint.