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
8c707c80
Commit
8c707c80
authored
Mar 22, 2016
by
Miek Gieben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more
parent
a6c3719b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
36 deletions
+54
-36
core/setup/etcd.go
core/setup/etcd.go
+26
-11
middleware/etcd/etcd.go
middleware/etcd/etcd.go
+10
-24
middleware/etcd/handler.go
middleware/etcd/handler.go
+4
-0
middleware/zone.go
middleware/zone.go
+14
-1
No files found.
core/setup/etcd.go
View file @
8c707c80
...
@@ -10,38 +10,53 @@ import (
...
@@ -10,38 +10,53 @@ import (
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware/etcd"
"github.com/miekg/coredns/middleware/etcd"
"github.com/miekg/coredns/middleware/etcd/singleflight"
"github.com/miekg/coredns/middleware/proxy"
etcdc
"github.com/coreos/etcd/client"
etcdc
"github.com/coreos/etcd/client"
"golang.org/x/net/context"
)
)
const
defaultEndpoint
=
"http://127.0.0.1:2379"
const
defaultEndpoint
=
"http://127.0.0.1:2379"
// Etcd sets up the etcd middleware.
// Etcd sets up the etcd middleware.
func
Etcd
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
func
Etcd
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
client
,
err
:=
etcdParse
(
c
)
etcd
,
err
:=
etcdParse
(
c
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
func
(
next
middleware
.
Handler
)
middleware
.
Handler
{
return
func
(
next
middleware
.
Handler
)
middleware
.
Handler
{
return
etcd
.
NewEtcd
(
client
,
next
,
c
.
ServerBlockHosts
)
etcd
.
Next
=
next
return
etcd
},
nil
},
nil
}
}
func
etcdParse
(
c
*
Controller
)
(
etcdc
.
KeysAPI
,
error
)
{
func
etcdParse
(
c
*
Controller
)
(
etcd
.
Etcd
,
error
)
{
etc
:=
etcd
.
Etcd
{
// make stuff configurable
Proxy
:
proxy
.
New
([]
string
{
"8.8.8.8:53"
}),
PathPrefix
:
"skydns"
,
Ctx
:
context
.
Background
(),
Inflight
:
&
singleflight
.
Group
{},
}
for
c
.
Next
()
{
for
c
.
Next
()
{
if
c
.
Val
()
==
"etcd"
{
if
c
.
Val
()
==
"etcd"
{
// etcd [address...]
// etcd [origin...]
if
!
c
.
NextArg
()
{
// TODO(certs) and friends, this is client side
client
,
err
:=
newEtcdClient
([]
string
{
defaultEndpoint
},
""
,
""
,
""
)
client
,
err
:=
newEtcdClient
([]
string
{
defaultEndpoint
},
""
,
""
,
""
)
return
client
,
err
if
err
!=
nil
{
return
etcd
.
Etcd
{},
err
}
etc
.
Client
=
client
etc
.
Zones
=
c
.
RemainingArgs
()
if
len
(
etc
.
Zones
)
==
0
{
etc
.
Zones
=
c
.
ServerBlockHosts
}
}
client
,
err
:=
newEtcdClient
(
c
.
RemainingArgs
(),
""
,
""
,
""
)
middleware
.
Zones
(
etc
.
Zones
)
.
FullyQualify
(
)
return
client
,
err
return
etc
,
nil
}
}
}
}
return
nil
,
nil
return
etcd
.
Etcd
{}
,
nil
}
}
func
newEtcdClient
(
endpoints
[]
string
,
tlsCert
,
tlsKey
,
tlsCACert
string
)
(
etcdc
.
KeysAPI
,
error
)
{
func
newEtcdClient
(
endpoints
[]
string
,
tlsCert
,
tlsKey
,
tlsCACert
string
)
(
etcdc
.
KeysAPI
,
error
)
{
...
...
middleware/etcd/etcd.go
View file @
8c707c80
...
@@ -14,28 +14,14 @@ import (
...
@@ -14,28 +14,14 @@ import (
"golang.org/x/net/context"
"golang.org/x/net/context"
)
)
type
(
type
Etcd
struct
{
Etcd
struct
{
Next
middleware
.
Handler
Next
middleware
.
Handler
Zones
[]
string
Zones
[]
string
Proxy
proxy
.
Proxy
Proxy
proxy
.
Proxy
c
lient
etcdc
.
KeysAPI
C
lient
etcdc
.
KeysAPI
c
tx
context
.
Context
C
tx
context
.
Context
i
nflight
*
singleflight
.
Group
I
nflight
*
singleflight
.
Group
PathPrefix
string
PathPrefix
string
}
)
func
NewEtcd
(
client
etcdc
.
KeysAPI
,
next
middleware
.
Handler
,
zones
[]
string
)
Etcd
{
return
Etcd
{
Next
:
next
,
Zones
:
zones
,
Proxy
:
proxy
.
New
([]
string
{
"8.8.8.8:53"
}),
client
:
client
,
ctx
:
context
.
Background
(),
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
)
{
...
@@ -57,8 +43,8 @@ func (g Etcd) Records(name string, exact bool) ([]msg.Service, error) {
...
@@ -57,8 +43,8 @@ func (g Etcd) Records(name string, exact bool) ([]msg.Service, error) {
// Get is a wrapper for client.Get that uses SingleInflight to suppress multiple outstanding queries.
// Get is a wrapper for client.Get that uses SingleInflight to suppress multiple outstanding queries.
func
(
g
Etcd
)
Get
(
path
string
,
recursive
bool
)
(
*
etcdc
.
Response
,
error
)
{
func
(
g
Etcd
)
Get
(
path
string
,
recursive
bool
)
(
*
etcdc
.
Response
,
error
)
{
resp
,
err
:=
g
.
i
nflight
.
Do
(
path
,
func
()
(
interface
{},
error
)
{
resp
,
err
:=
g
.
I
nflight
.
Do
(
path
,
func
()
(
interface
{},
error
)
{
r
,
e
:=
g
.
client
.
Get
(
g
.
c
tx
,
path
,
&
etcdc
.
GetOptions
{
Sort
:
false
,
Recursive
:
recursive
})
r
,
e
:=
g
.
Client
.
Get
(
g
.
C
tx
,
path
,
&
etcdc
.
GetOptions
{
Sort
:
false
,
Recursive
:
recursive
})
if
e
!=
nil
{
if
e
!=
nil
{
return
nil
,
e
return
nil
,
e
}
}
...
...
middleware/etcd/handler.go
View file @
8c707c80
...
@@ -2,6 +2,7 @@ package etcd
...
@@ -2,6 +2,7 @@ package etcd
import
(
import
(
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware"
"github.com/miekg/dns"
"github.com/miekg/dns"
"golang.org/x/net/context"
"golang.org/x/net/context"
)
)
...
@@ -35,6 +36,9 @@ func (e Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
...
@@ -35,6 +36,9 @@ func (e Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
case
"SRV"
:
case
"SRV"
:
records
,
extra
,
err
=
e
.
SRV
(
zone
,
state
)
records
,
extra
,
err
=
e
.
SRV
(
zone
,
state
)
default
:
default
:
// For SOA and NS we might still want this
// and use dns.<zones> as the name to put these
// also for stub
// rwrite and return
// rwrite and return
// Nodata response
// Nodata response
// also catch other types, so that they return NODATA
// also catch other types, so that they return NODATA
...
...
middleware/zone.go
View file @
8c707c80
package
middleware
package
middleware
import
"strings"
import
(
"strings"
"github.com/miekg/dns"
)
type
Zones
[]
string
type
Zones
[]
string
...
@@ -11,6 +15,7 @@ func (z Zones) Matches(qname string) string {
...
@@ -11,6 +15,7 @@ func (z Zones) Matches(qname string) string {
zone
:=
""
zone
:=
""
// TODO(miek): use IsSubDomain here?
// TODO(miek): use IsSubDomain here?
for
_
,
zname
:=
range
z
{
for
_
,
zname
:=
range
z
{
println
(
zname
,
qname
)
if
strings
.
HasSuffix
(
qname
,
zname
)
{
if
strings
.
HasSuffix
(
qname
,
zname
)
{
if
len
(
zname
)
>
len
(
zone
)
{
if
len
(
zname
)
>
len
(
zone
)
{
zone
=
zname
zone
=
zname
...
@@ -19,3 +24,11 @@ func (z Zones) Matches(qname string) string {
...
@@ -19,3 +24,11 @@ func (z Zones) Matches(qname string) string {
}
}
return
zone
return
zone
}
}
// Fully qualify all zones in z
func
(
z
Zones
)
FullyQualify
()
{
for
i
,
_
:=
range
z
{
z
[
i
]
=
dns
.
Fqdn
(
z
[
i
])
}
}
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