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
0c94de4f
Commit
0c94de4f
authored
Mar 20, 2016
by
Miek Gieben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More stuff copied from SkyDNS
parent
e00e002f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
32 deletions
+74
-32
core/setup/etcd.go
core/setup/etcd.go
+57
-26
middleware/etcd/etcd.go
middleware/etcd/etcd.go
+9
-3
middleware/etcd/etcd.md
middleware/etcd/etcd.md
+8
-3
No files found.
core/setup/etcd.go
View file @
0c94de4f
package
setup
package
setup
import
(
import
(
"log"
"crypto/tls"
"os"
"crypto/x509"
"io/ioutil"
"net"
"net/http"
"time"
etcdc
"github.com/coreos/etcd/client"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware/file"
"github.com/miekg/coredns/middleware/file"
"github.com/miekg/dns"
)
)
// File sets up the file middleware.
const
defaultAddress
=
"http://127.0.0.1:2379"
func
File
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
zones
,
err
:=
fileParse
(
c
)
// Etcd sets up the etcd middleware.
func
Etcd
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
keysapi
,
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
file
.
File
{
Next
:
next
,
Zones
:
zones
}
return
file
.
File
{
Next
:
next
,
Zones
:
zones
}
},
nil
},
nil
}
}
func
fileParse
(
c
*
Controller
)
(
file
.
Zones
,
error
)
{
func
etcdParse
(
c
*
Controller
)
(
etcdc
.
KeysAPI
,
error
)
{
// Maybe multiple, each for each zone.
z
:=
make
(
map
[
string
]
file
.
Zone
)
names
:=
[]
string
{}
for
c
.
Next
()
{
for
c
.
Next
()
{
if
c
.
Val
()
==
"
file
"
{
if
c
.
Val
()
==
"
etcd
"
{
//
file db.file [origin
]
//
etcd [address...
]
if
!
c
.
NextArg
()
{
if
!
c
.
NextArg
()
{
return
file
.
Zones
{},
c
.
ArgErr
()
return
file
.
Zones
{},
c
.
ArgErr
()
}
}
args1
:=
c
.
RemainingArgs
()
fileName
:=
c
.
Val
()
fileName
:=
c
.
Val
()
origin
:=
c
.
ServerBlockHosts
[
c
.
ServerBlockHostIndex
]
origin
:=
c
.
ServerBlockHosts
[
c
.
ServerBlockHostIndex
]
...
@@ -51,23 +57,48 @@ func fileParse(c *Controller) (file.Zones, error) {
...
@@ -51,23 +57,48 @@ func fileParse(c *Controller) (file.Zones, error) {
return
file
.
Zones
{
Z
:
z
,
Names
:
names
},
nil
return
file
.
Zones
{
Z
:
z
,
Names
:
names
},
nil
}
}
//
func
newEtcdClient
(
machines
[]
string
,
tlsCert
,
tlsKey
,
tlsCACert
string
)
(
etcd
.
KeysAPI
,
error
)
{
// parsrZone parses the zone in filename and returns a []RR or an error.
etcdCfg
:=
etcd
.
Config
{
func
parseZone
(
origin
,
fileName
string
)
(
file
.
Zone
,
error
)
{
Endpoints
:
machines
,
f
,
err
:=
os
.
Open
(
fileName
)
Transport
:
newHTTPSTransport
(
tlsCert
,
tlsKey
,
tlsCACert
),
}
cli
,
err
:=
etcd
.
New
(
etcdCfg
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
tokens
:=
dns
.
ParseZone
(
f
,
origin
,
fileName
)
return
etcd
.
NewKeysAPI
(
cli
),
nil
zone
:=
make
([]
dns
.
RR
,
0
,
defaultZoneSize
)
}
for
x
:=
range
tokens
{
if
x
.
Error
!=
nil
{
func
newHTTPSTransport
(
tlsCertFile
,
tlsKeyFile
,
tlsCACertFile
string
)
etcd
.
CancelableTransport
{
log
.
Printf
(
"[ERROR] failed to parse %s: %v"
,
origin
,
x
.
Error
)
var
cc
*
tls
.
Config
=
nil
return
nil
,
x
.
Error
if
tlsCertFile
!=
""
&&
tlsKeyFile
!=
""
{
var
rpool
*
x509
.
CertPool
if
tlsCACertFile
!=
""
{
if
pemBytes
,
err
:=
ioutil
.
ReadFile
(
tlsCACertFile
);
err
==
nil
{
rpool
=
x509
.
NewCertPool
()
rpool
.
AppendCertsFromPEM
(
pemBytes
)
}
}
zone
=
append
(
zone
,
x
.
RR
)
}
}
return
file
.
Zone
(
zone
),
nil
}
const
defaultZoneSize
=
20
// A made up number.
if
tlsCert
,
err
:=
tls
.
LoadX509KeyPair
(
tlsCertFile
,
tlsKeyFile
);
err
==
nil
{
cc
=
&
tls
.
Config
{
RootCAs
:
rpool
,
Certificates
:
[]
tls
.
Certificate
{
tlsCert
},
InsecureSkipVerify
:
true
,
}
}
}
tr
:=
&
http
.
Transport
{
Proxy
:
http
.
ProxyFromEnvironment
,
Dial
:
(
&
net
.
Dialer
{
Timeout
:
30
*
time
.
Second
,
KeepAlive
:
30
*
time
.
Second
,
})
.
Dial
,
TLSHandshakeTimeout
:
10
*
time
.
Second
,
TLSClientConfig
:
cc
,
}
return
tr
}
middleware/etcd/etcd.go
View file @
0c94de4f
...
@@ -3,9 +3,10 @@ package etcd
...
@@ -3,9 +3,10 @@ package etcd
import
(
import
(
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware"
"github.com/miekg/dns"
"github.com/skynetservices/skydns/singleflight"
"github.com/skynetservices/skydns/singleflight"
etcd
"github.com/coreos/etcd/client"
etcd
c
"github.com/coreos/etcd/client"
"golang.org/x/net/context"
"golang.org/x/net/context"
)
)
...
@@ -19,10 +20,15 @@ type (
...
@@ -19,10 +20,15 @@ type (
}
}
)
)
func
NewEtcd
(
client
etcd
.
KeysAPI
,
ctx
context
.
Context
)
Etcd
{
func
NewEtcd
(
client
etcd
c
.
KeysAPI
,
next
middleware
.
Handler
)
Etcd
{
return
Etcd
{
return
Etcd
{
Next
:
next
,
client
:
client
,
client
:
client
,
ctx
:
c
tx
,
ctx
:
c
ontext
.
Background
()
,
inflight
:
&
singleflight
.
Group
{},
inflight
:
&
singleflight
.
Group
{},
}
}
}
}
func
(
e
Etcd
)
ServerDNS
(
ctx
context
.
Context
,
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
(
int
,
error
)
{
return
0
,
nil
}
middleware/etcd/etcd.md
View file @
0c94de4f
...
@@ -7,10 +7,10 @@ like SkyDNS.
...
@@ -7,10 +7,10 @@ like SkyDNS.
## Syntax
## Syntax
~~~
~~~
etcd [
address
...]
etcd [
endpoint
...]
~~~
~~~
*
`
address
`
is the endpoint of etcd.
*
`
endpoint
`
is the endpoint of etcd.
The will default to
`/skydns`
as the path and the local etcd proxy (http://127.0.0.1:2379).
The will default to
`/skydns`
as the path and the local etcd proxy (http://127.0.0.1:2379).
...
@@ -18,9 +18,14 @@ The will default to `/skydns` as the path and the local etcd proxy (http://127.0
...
@@ -18,9 +18,14 @@ The will default to `/skydns` as the path and the local etcd proxy (http://127.0
etcd {
etcd {
round_robin
round_robin
path /skydns
path /skydns
address
address...
endpoint
address...
stubzones
stubzones
}
}
~~~
~~~
*
`round_robin`
*
`path`
/skydns
*
`endpoint`
address...
*
`stubzones`
## Examples
## Examples
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