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
e00e002f
Commit
e00e002f
authored
Mar 20, 2016
by
Miek Gieben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more
parent
57d45cbb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
16 deletions
+88
-16
core/setup/etcd.go
core/setup/etcd.go
+73
-0
middleware/etcd/backend.go
middleware/etcd/backend.go
+7
-2
middleware/etcd/etcd.go
middleware/etcd/etcd.go
+8
-14
No files found.
core/setup/etcd.go
0 → 100644
View file @
e00e002f
package
setup
import
(
"log"
"os"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware/file"
"github.com/miekg/dns"
)
// File sets up the file middleware.
func
File
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
zones
,
err
:=
fileParse
(
c
)
if
err
!=
nil
{
return
nil
,
err
}
return
func
(
next
middleware
.
Handler
)
middleware
.
Handler
{
return
file
.
File
{
Next
:
next
,
Zones
:
zones
}
},
nil
}
func
fileParse
(
c
*
Controller
)
(
file
.
Zones
,
error
)
{
// Maybe multiple, each for each zone.
z
:=
make
(
map
[
string
]
file
.
Zone
)
names
:=
[]
string
{}
for
c
.
Next
()
{
if
c
.
Val
()
==
"file"
{
// file db.file [origin]
if
!
c
.
NextArg
()
{
return
file
.
Zones
{},
c
.
ArgErr
()
}
fileName
:=
c
.
Val
()
origin
:=
c
.
ServerBlockHosts
[
c
.
ServerBlockHostIndex
]
if
c
.
NextArg
()
{
c
.
Next
()
origin
=
c
.
Val
()
}
// normalize this origin
origin
=
middleware
.
Host
(
origin
)
.
StandardHost
()
zone
,
err
:=
parseZone
(
origin
,
fileName
)
if
err
==
nil
{
z
[
origin
]
=
zone
}
names
=
append
(
names
,
origin
)
}
}
return
file
.
Zones
{
Z
:
z
,
Names
:
names
},
nil
}
//
// parsrZone parses the zone in filename and returns a []RR or an error.
func
parseZone
(
origin
,
fileName
string
)
(
file
.
Zone
,
error
)
{
f
,
err
:=
os
.
Open
(
fileName
)
if
err
!=
nil
{
return
nil
,
err
}
tokens
:=
dns
.
ParseZone
(
f
,
origin
,
fileName
)
zone
:=
make
([]
dns
.
RR
,
0
,
defaultZoneSize
)
for
x
:=
range
tokens
{
if
x
.
Error
!=
nil
{
log
.
Printf
(
"[ERROR] failed to parse %s: %v"
,
origin
,
x
.
Error
)
return
nil
,
x
.
Error
}
zone
=
append
(
zone
,
x
.
RR
)
}
return
file
.
Zone
(
zone
),
nil
}
const
defaultZoneSize
=
20
// A made up number.
middleware/etcd/backend.go
View file @
e00e002f
...
...
@@ -11,6 +11,11 @@ import (
etcdc
"github.com/coreos/etcd/client"
)
const
(
priority
=
10
// default priority when nothing is set
ttl
=
3600
// default ttl when nothing is set
)
func
(
g
*
Backend
)
Records
(
name
string
,
exact
bool
)
([]
msg
.
Service
,
error
)
{
path
,
star
:=
msg
.
PathWithWildcard
(
name
)
r
,
err
:=
g
.
get
(
path
,
true
)
...
...
@@ -125,7 +130,7 @@ Nodes:
serv
.
Key
=
n
.
Key
serv
.
Ttl
=
g
.
calculateTtl
(
n
,
serv
)
if
serv
.
Priority
==
0
{
serv
.
Priority
=
int
(
g
.
config
.
Priority
)
serv
.
Priority
=
priority
}
sx
=
append
(
sx
,
*
serv
)
}
...
...
@@ -139,7 +144,7 @@ func (g *Backend) calculateTtl(node *etcdc.Node, serv *msg.Service) uint32 {
etcdTtl
:=
uint32
(
node
.
TTL
)
if
etcdTtl
==
0
&&
serv
.
Ttl
==
0
{
return
g
.
config
.
T
tl
return
t
tl
}
if
etcdTtl
==
0
{
return
serv
.
Ttl
...
...
middleware/etcd/etcd.go
View file @
e00e002f
...
...
@@ -2,6 +2,7 @@
package
etcd
import
(
"github.com/miekg/coredns/middleware"
"github.com/skynetservices/skydns/singleflight"
etcd
"github.com/coreos/etcd/client"
...
...
@@ -10,25 +11,18 @@ import (
type
(
Etcd
struct
{
Ttl
uint32
Priority
uint16
Backend
*
Backend
Next
middleware
.
Handler
client
etcd
.
KeysAPI
ctx
context
.
Context
inflight
*
singleflight
.
Group
}
)
type
Backend
struct
{
client
etcd
.
KeysAPI
ctx
context
.
Context
config
*
Config
inflight
*
singleflight
.
Group
}
// NewBackend returns a new Backend.
func
NewBackend
(
client
etcd
.
KeysAPI
,
ctx
context
.
Context
,
config
*
Config
)
*
Backend
{
return
&
Backend
{
func
NewEtcd
(
client
etcd
.
KeysAPI
,
ctx
context
.
Context
)
Etcd
{
return
Etcd
{
client
:
client
,
ctx
:
ctx
,
config
:
config
,
inflight
:
&
singleflight
.
Group
{},
}
}
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