Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
ecc5f286
Commit
ecc5f286
authored
Mar 21, 2016
by
Miek Gieben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Path stuff copied over and tests added
parent
b6341e8b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
54 deletions
+73
-54
middleware/etcd/etcd.go
middleware/etcd/etcd.go
+14
-12
middleware/etcd/msg/service.go
middleware/etcd/msg/service.go
+0
-42
middleware/etcd/path.go
middleware/etcd/path.go
+46
-0
middleware/etcd/path_test.go
middleware/etcd/path_test.go
+13
-0
No files found.
middleware/etcd/etcd.go
View file @
ecc5f286
...
@@ -15,31 +15,33 @@ import (
...
@@ -15,31 +15,33 @@ import (
type
(
type
(
Etcd
struct
{
Etcd
struct
{
Next
middleware
.
Handler
Next
middleware
.
Handler
Zones
[]
string
Zones
[]
string
client
etcdc
.
KeysAPI
client
etcdc
.
KeysAPI
ctx
context
.
Context
ctx
context
.
Context
inflight
*
singleflight
.
Group
inflight
*
singleflight
.
Group
PathPrefix
string
}
}
)
)
func
NewEtcd
(
client
etcdc
.
KeysAPI
,
next
middleware
.
Handler
,
zones
[]
string
)
Etcd
{
func
NewEtcd
(
client
etcdc
.
KeysAPI
,
next
middleware
.
Handler
,
zones
[]
string
)
Etcd
{
return
Etcd
{
return
Etcd
{
Next
:
next
,
Next
:
next
,
Zones
:
zones
,
Zones
:
zones
,
client
:
client
,
client
:
client
,
ctx
:
context
.
Background
(),
ctx
:
context
.
Background
(),
inflight
:
&
singleflight
.
Group
{},
inflight
:
&
singleflight
.
Group
{},
PathPrefix
:
"skydns"
,
// TODO(miek): configurable
}
}
}
}
func
(
g
Etcd
)
Records
(
name
string
,
exact
bool
)
([]
msg
.
Service
,
error
)
{
func
(
g
Etcd
)
Records
(
name
string
,
exact
bool
)
([]
msg
.
Service
,
error
)
{
path
,
star
:=
ms
g
.
PathWithWildcard
(
name
)
path
,
star
:=
g
.
PathWithWildcard
(
name
)
r
,
err
:=
g
.
Get
(
path
,
true
)
r
,
err
:=
g
.
Get
(
path
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
segments
:=
strings
.
Split
(
ms
g
.
Path
(
name
),
"/"
)
segments
:=
strings
.
Split
(
g
.
Path
(
name
),
"/"
)
switch
{
switch
{
case
exact
&&
r
.
Node
.
Dir
:
case
exact
&&
r
.
Node
.
Dir
:
return
nil
,
nil
return
nil
,
nil
...
...
middleware/etcd/msg/service.go
View file @
ecc5f286
...
@@ -2,15 +2,11 @@ package msg
...
@@ -2,15 +2,11 @@ package msg
import
(
import
(
"net"
"net"
"path"
"strings"
"strings"
"github.com/miekg/dns"
"github.com/miekg/dns"
)
)
// PathPrefix is the prefix used to store CoreDNS data in etcd.
var
PathPrefix
string
=
"skydns"
// This *is* the rdata from a SRV record, but with a twist.
// This *is* the rdata from a SRV record, but with a twist.
// Host (Target in SRV) must be a domain name, but if it looks like an IP
// Host (Target in SRV) must be a domain name, but if it looks like an IP
// address (4/6), we will treat it like an IP address.
// address (4/6), we will treat it like an IP address.
...
@@ -85,44 +81,6 @@ func (s *Service) NewPTR(name string, ttl uint32) *dns.PTR {
...
@@ -85,44 +81,6 @@ func (s *Service) NewPTR(name string, ttl uint32) *dns.PTR {
return
&
dns
.
PTR
{
Hdr
:
dns
.
RR_Header
{
Name
:
name
,
Rrtype
:
dns
.
TypePTR
,
Class
:
dns
.
ClassINET
,
Ttl
:
ttl
},
Ptr
:
dns
.
Fqdn
(
s
.
Host
)}
return
&
dns
.
PTR
{
Hdr
:
dns
.
RR_Header
{
Name
:
name
,
Rrtype
:
dns
.
TypePTR
,
Class
:
dns
.
ClassINET
,
Ttl
:
ttl
},
Ptr
:
dns
.
Fqdn
(
s
.
Host
)}
}
}
// As Path, but if a name contains wildcards (* or any), the name will be
// chopped of before the (first) wildcard, and we do a highler evel search and
// later find the matching names. So service.*.skydns.local, will look for all
// services under skydns.local and will later check for names that match
// service.*.skydns.local. If a wildcard is found the returned bool is true.
func
PathWithWildcard
(
s
string
)
(
string
,
bool
)
{
l
:=
dns
.
SplitDomainName
(
s
)
for
i
,
j
:=
0
,
len
(
l
)
-
1
;
i
<
j
;
i
,
j
=
i
+
1
,
j
-
1
{
l
[
i
],
l
[
j
]
=
l
[
j
],
l
[
i
]
}
for
i
,
k
:=
range
l
{
if
k
==
"*"
||
k
==
"any"
{
return
path
.
Join
(
append
([]
string
{
"/"
+
PathPrefix
+
"/"
},
l
[
:
i
]
...
)
...
),
true
}
}
return
path
.
Join
(
append
([]
string
{
"/"
+
PathPrefix
+
"/"
},
l
...
)
...
),
false
}
// Path converts a domainname to an etcd path. If s looks like service.staging.skydns.local.,
// the resulting key will be /skydns/local/skydns/staging/service .
func
Path
(
s
string
)
string
{
l
:=
dns
.
SplitDomainName
(
s
)
for
i
,
j
:=
0
,
len
(
l
)
-
1
;
i
<
j
;
i
,
j
=
i
+
1
,
j
-
1
{
l
[
i
],
l
[
j
]
=
l
[
j
],
l
[
i
]
}
return
path
.
Join
(
append
([]
string
{
"/"
+
PathPrefix
+
"/"
},
l
...
)
...
)
}
// Domain is the opposite of Path.
func
Domain
(
s
string
)
string
{
l
:=
strings
.
Split
(
s
,
"/"
)
// start with 1, to strip /skydns
for
i
,
j
:=
1
,
len
(
l
)
-
1
;
i
<
j
;
i
,
j
=
i
+
1
,
j
-
1
{
l
[
i
],
l
[
j
]
=
l
[
j
],
l
[
i
]
}
return
dns
.
Fqdn
(
strings
.
Join
(
l
[
1
:
len
(
l
)
-
1
],
"."
))
}
// Group checks the services in sx, it looks for a Group attribute on the shortest
// Group checks the services in sx, it looks for a Group attribute on the shortest
// keys. If there are multiple shortest keys *and* the group attribute disagrees (and
// keys. If there are multiple shortest keys *and* the group attribute disagrees (and
// is not empty), we don't consider it a group.
// is not empty), we don't consider it a group.
...
...
middleware/etcd/path.go
0 → 100644
View file @
ecc5f286
package
etcd
import
(
"path"
"strings"
"github.com/miekg/dns"
)
// Path converts a domainname to an etcd path. If s looks like service.staging.skydns.local.,
// the resulting key will be /skydns/local/skydns/staging/service .
func
(
e
Etcd
)
Path
(
s
string
)
string
{
l
:=
dns
.
SplitDomainName
(
s
)
for
i
,
j
:=
0
,
len
(
l
)
-
1
;
i
<
j
;
i
,
j
=
i
+
1
,
j
-
1
{
l
[
i
],
l
[
j
]
=
l
[
j
],
l
[
i
]
}
return
path
.
Join
(
append
([]
string
{
"/"
+
e
.
PathPrefix
+
"/"
},
l
...
)
...
)
}
// Domain is the opposite of Path.
func
(
e
Etcd
)
Domain
(
s
string
)
string
{
l
:=
strings
.
Split
(
s
,
"/"
)
// start with 1, to strip /skydns
for
i
,
j
:=
1
,
len
(
l
)
-
1
;
i
<
j
;
i
,
j
=
i
+
1
,
j
-
1
{
l
[
i
],
l
[
j
]
=
l
[
j
],
l
[
i
]
}
return
dns
.
Fqdn
(
strings
.
Join
(
l
[
1
:
len
(
l
)
-
1
],
"."
))
}
// As Path, but if a name contains wildcards (* or any), the name will be
// chopped of before the (first) wildcard, and we do a highler evel search and
// later find the matching names. So service.*.skydns.local, will look for all
// services under skydns.local and will later check for names that match
// service.*.skydns.local. If a wildcard is found the returned bool is true.
func
(
e
Etcd
)
PathWithWildcard
(
s
string
)
(
string
,
bool
)
{
l
:=
dns
.
SplitDomainName
(
s
)
for
i
,
j
:=
0
,
len
(
l
)
-
1
;
i
<
j
;
i
,
j
=
i
+
1
,
j
-
1
{
l
[
i
],
l
[
j
]
=
l
[
j
],
l
[
i
]
}
for
i
,
k
:=
range
l
{
if
k
==
"*"
||
k
==
"any"
{
return
path
.
Join
(
append
([]
string
{
"/"
+
e
.
PathPrefix
+
"/"
},
l
[
:
i
]
...
)
...
),
true
}
}
return
path
.
Join
(
append
([]
string
{
"/"
+
e
.
PathPrefix
+
"/"
},
l
...
)
...
),
false
}
middleware/etcd/path_test.go
0 → 100644
View file @
ecc5f286
package
etcd
import
"testing"
func
TestPath
(
t
*
testing
.
T
)
{
for
path
:=
range
[]
string
{
"mydns"
,
"skydns"
}
{
e
:=
Etcd
{
PathPrefix
:
"mydns"
}
result
:=
e
.
Path
(
"service.staging.skydns.local."
)
if
result
!=
"/"
+
path
+
"/"
+
"/local/skydns/staging/service"
{
t
.
Errorf
(
"Failure to get domain's path with prefix: %s"
,
path
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment