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
362d7e96
Commit
362d7e96
authored
Feb 17, 2019
by
mrasu
Committed by
corbot[bot]
Feb 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugin/auto: Reload zones every one minute (#2516)
Automatically submitted.
parent
643dfd74
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
24 deletions
+66
-24
plugin/auto/README.md
plugin/auto/README.md
+6
-4
plugin/auto/setup.go
plugin/auto/setup.go
+19
-2
plugin/auto/setup_test.go
plugin/auto/setup_test.go
+41
-18
No files found.
plugin/auto/README.md
View file @
362d7e96
...
@@ -29,10 +29,12 @@ are used.
...
@@ -29,10 +29,12 @@ are used.
used to extract the origin.
**ORIGIN_TEMPLATE**
will be used as a template for the origin. Strings
used to extract the origin.
**ORIGIN_TEMPLATE**
will be used as a template for the origin. Strings
like
`{<number>}`
are replaced with the respective matches in the file name, e.g.
`{1}`
is the
like
`{<number>}`
are replaced with the respective matches in the file name, e.g.
`{1}`
is the
first match,
`{2}`
is the second. The default is:
`db\.(.*) {1}`
i.e. from a file with the
first match,
`{2}`
is the second. The default is:
`db\.(.*) {1}`
i.e. from a file with the
name
`db.example.com`
, the extracted origin will be
`example.com`
.
**TIMEOUT**
specifies how often
name
`db.example.com`
, the extracted origin will be
`example.com`
.
CoreDNS should scan the directory; the default is every 60 seconds. This value is in seconds.
**TIMEOUT**
is deprecated and will be removed in a subsequent version.
The minimum value is 1 second.
`reload`
will be used, if not defined
*
`reload`
interval to perform reload of zone if SOA version changes. Default is one minute.
(it specifies how often CoreDNS should scan the directory to watch for file removal and addition;
the default is every 60 seconds. This value is in seconds. The minimum value is 1 second.)
*
`reload`
interval to perform reloads of zones if SOA version changes and zonefiles. Default is one minute.
Value of
`0`
means to not scan for changes and reload. eg.
`30s`
checks zonefile every 30 seconds
Value of
`0`
means to not scan for changes and reload. eg.
`30s`
checks zonefile every 30 seconds
and reloads zone when serial changes.
and reloads zone when serial changes.
*
`no_reload`
deprecated. Sets reload to 0.
*
`no_reload`
deprecated. Sets reload to 0.
...
...
plugin/auto/setup.go
View file @
362d7e96
...
@@ -77,9 +77,15 @@ func setup(c *caddy.Controller) error {
...
@@ -77,9 +77,15 @@ func setup(c *caddy.Controller) error {
}
}
func
autoParse
(
c
*
caddy
.
Controller
)
(
Auto
,
error
)
{
func
autoParse
(
c
*
caddy
.
Controller
)
(
Auto
,
error
)
{
nilInterval
:=
-
1
*
time
.
Second
var
a
=
Auto
{
var
a
=
Auto
{
loader
:
loader
{
template
:
"${1}"
,
re
:
regexp
.
MustCompile
(
`db\.(.*)`
),
duration
:
60
*
time
.
Second
},
loader
:
loader
{
Zones
:
&
Zones
{},
template
:
"${1}"
,
re
:
regexp
.
MustCompile
(
`db\.(.*)`
),
ReloadInterval
:
nilInterval
,
duration
:
nilInterval
,
},
Zones
:
&
Zones
{},
}
}
config
:=
dnsserver
.
GetConfig
(
c
)
config
:=
dnsserver
.
GetConfig
(
c
)
...
@@ -141,6 +147,7 @@ func autoParse(c *caddy.Controller) (Auto, error) {
...
@@ -141,6 +147,7 @@ func autoParse(c *caddy.Controller) (Auto, error) {
if
i
<
1
{
if
i
<
1
{
i
=
1
i
=
1
}
}
log
.
Warning
(
"TIMEOUT of directory is deprecated. Use RELOAD instead. See https://coredns.io/plugins/auto/#syntax"
)
a
.
loader
.
duration
=
time
.
Duration
(
i
)
*
time
.
Second
a
.
loader
.
duration
=
time
.
Duration
(
i
)
*
time
.
Second
}
}
...
@@ -169,5 +176,15 @@ func autoParse(c *caddy.Controller) (Auto, error) {
...
@@ -169,5 +176,15 @@ func autoParse(c *caddy.Controller) (Auto, error) {
}
}
}
}
}
}
if
a
.
loader
.
ReloadInterval
==
nilInterval
{
if
a
.
loader
.
duration
==
nilInterval
{
a
.
loader
.
duration
=
60
*
time
.
Second
}
a
.
loader
.
ReloadInterval
=
a
.
loader
.
duration
}
else
if
a
.
loader
.
duration
==
nilInterval
{
a
.
loader
.
duration
=
a
.
loader
.
ReloadInterval
}
return
a
,
nil
return
a
,
nil
}
}
plugin/auto/setup_test.go
View file @
362d7e96
...
@@ -2,50 +2,67 @@ package auto
...
@@ -2,50 +2,67 @@ package auto
import
(
import
(
"testing"
"testing"
"time"
"github.com/mholt/caddy"
"github.com/mholt/caddy"
)
)
func
TestAutoParse
(
t
*
testing
.
T
)
{
func
TestAutoParse
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
inputFileRules
string
inputFileRules
string
shouldErr
bool
shouldErr
bool
expectedDirectory
string
expectedDirectory
string
expectedTempl
string
expectedTempl
string
expectedRe
string
expectedRe
string
expectedTo
[]
string
expectedReloadInterval
time
.
Duration
expectedDuration
time
.
Duration
expectedTo
[]
string
}{
}{
{
{
`auto example.org {
`auto example.org {
directory /tmp
directory /tmp
transfer to 127.0.0.1
transfer to 127.0.0.1
}`
,
}`
,
false
,
"/tmp"
,
"${1}"
,
`db\.(.*)`
,
[]
string
{
"127.0.0.1:53"
},
false
,
"/tmp"
,
"${1}"
,
`db\.(.*)`
,
60
*
time
.
Second
,
60
*
time
.
Second
,
[]
string
{
"127.0.0.1:53"
},
},
},
{
{
`auto 10.0.0.0/24 {
`auto 10.0.0.0/24 {
directory /tmp
directory /tmp
}`
,
}`
,
false
,
"/tmp"
,
"${1}"
,
`db\.(.*)`
,
nil
,
false
,
"/tmp"
,
"${1}"
,
`db\.(.*)`
,
60
*
time
.
Second
,
60
*
time
.
Second
,
nil
,
},
},
{
{
`auto {
`auto {
directory /tmp
directory /tmp
no_reload
no_reload
}`
,
}`
,
false
,
"/tmp"
,
"${1}"
,
`db\.(.*)`
,
nil
,
false
,
"/tmp"
,
"${1}"
,
`db\.(.*)`
,
0
*
time
.
Second
,
0
*
time
.
Second
,
nil
,
},
},
{
{
`auto {
`auto {
directory /tmp (.*) bliep
directory /tmp (.*) bliep
}`
,
}`
,
false
,
"/tmp"
,
"bliep"
,
`(.*)`
,
nil
,
false
,
"/tmp"
,
"bliep"
,
`(.*)`
,
60
*
time
.
Second
,
60
*
time
.
Second
,
nil
,
},
},
{
{
`auto {
`auto {
directory /tmp (.*) bliep 10
directory /tmp (.*) bliep 10
}`
,
}`
,
false
,
"/tmp"
,
"bliep"
,
`(.*)`
,
nil
,
false
,
"/tmp"
,
"bliep"
,
`(.*)`
,
10
*
time
.
Second
,
10
*
time
.
Second
,
nil
,
},
{
`auto {
directory /tmp (.*) bliep
reload 10s
}`
,
false
,
"/tmp"
,
"bliep"
,
`(.*)`
,
10
*
time
.
Second
,
10
*
time
.
Second
,
nil
,
},
{
`auto {
directory /tmp (.*) bliep 20
reload 10s
}`
,
false
,
"/tmp"
,
"bliep"
,
`(.*)`
,
10
*
time
.
Second
,
20
*
time
.
Second
,
nil
,
},
},
{
{
`auto {
`auto {
...
@@ -54,44 +71,44 @@ func TestAutoParse(t *testing.T) {
...
@@ -54,44 +71,44 @@ func TestAutoParse(t *testing.T) {
transfer to 127.0.0.2
transfer to 127.0.0.2
upstream 8.8.8.8
upstream 8.8.8.8
}`
,
}`
,
false
,
"/tmp"
,
"bliep"
,
`(.*)`
,
[]
string
{
"127.0.0.1:53"
,
"127.0.0.2:53"
},
false
,
"/tmp"
,
"bliep"
,
`(.*)`
,
60
*
time
.
Second
,
60
*
time
.
Second
,
[]
string
{
"127.0.0.1:53"
,
"127.0.0.2:53"
},
},
},
// errors
// errors
{
{
`auto example.org {
`auto example.org {
directory
directory
}`
,
}`
,
true
,
""
,
"${1}"
,
`db\.(.*)`
,
nil
,
true
,
""
,
"${1}"
,
`db\.(.*)`
,
60
*
time
.
Second
,
60
*
time
.
Second
,
nil
,
},
},
{
{
`auto example.org {
`auto example.org {
directory /tmp * {1}
directory /tmp * {1}
}`
,
}`
,
true
,
""
,
"${1}"
,
``
,
nil
,
true
,
""
,
"${1}"
,
``
,
60
*
time
.
Second
,
60
*
time
.
Second
,
nil
,
},
},
{
{
`auto example.org {
`auto example.org {
directory /tmp * {1} aa
directory /tmp * {1} aa
}`
,
}`
,
true
,
""
,
"${1}"
,
``
,
nil
,
true
,
""
,
"${1}"
,
``
,
60
*
time
.
Second
,
60
*
time
.
Second
,
nil
,
},
},
{
{
`auto example.org {
`auto example.org {
directory /tmp .* {1}
directory /tmp .* {1}
}`
,
}`
,
true
,
""
,
"${1}"
,
``
,
nil
,
true
,
""
,
"${1}"
,
``
,
60
*
time
.
Second
,
60
*
time
.
Second
,
nil
,
},
},
{
{
`auto example.org {
`auto example.org {
directory /tmp .* {1}
directory /tmp .* {1}
}`
,
}`
,
true
,
""
,
"${1}"
,
``
,
nil
,
true
,
""
,
"${1}"
,
``
,
60
*
time
.
Second
,
60
*
time
.
Second
,
nil
,
},
},
{
{
`auto example.org {
`auto example.org {
directory /tmp .* {1}
directory /tmp .* {1}
}`
,
}`
,
true
,
""
,
"${1}"
,
``
,
nil
,
true
,
""
,
"${1}"
,
``
,
60
*
time
.
Second
,
60
*
time
.
Second
,
nil
,
},
},
}
}
...
@@ -113,6 +130,12 @@ func TestAutoParse(t *testing.T) {
...
@@ -113,6 +130,12 @@ func TestAutoParse(t *testing.T) {
if
a
.
loader
.
re
.
String
()
!=
test
.
expectedRe
{
if
a
.
loader
.
re
.
String
()
!=
test
.
expectedRe
{
t
.
Fatalf
(
"Test %d expected %v, got %v"
,
i
,
test
.
expectedRe
,
a
.
loader
.
re
)
t
.
Fatalf
(
"Test %d expected %v, got %v"
,
i
,
test
.
expectedRe
,
a
.
loader
.
re
)
}
}
if
a
.
loader
.
ReloadInterval
!=
test
.
expectedReloadInterval
{
t
.
Fatalf
(
"Test %d expected %v, got %v"
,
i
,
test
.
expectedReloadInterval
,
a
.
loader
.
ReloadInterval
)
}
if
a
.
loader
.
duration
!=
test
.
expectedDuration
{
t
.
Fatalf
(
"Test %d expected %v, got %v"
,
i
,
test
.
expectedDuration
,
a
.
loader
.
duration
)
}
if
test
.
expectedTo
!=
nil
{
if
test
.
expectedTo
!=
nil
{
for
j
,
got
:=
range
a
.
loader
.
transferTo
{
for
j
,
got
:=
range
a
.
loader
.
transferTo
{
if
got
!=
test
.
expectedTo
[
j
]
{
if
got
!=
test
.
expectedTo
[
j
]
{
...
...
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