aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorGravatar mrasu <m.rasu.hitsuji@gmail.com> 2019-02-17 23:51:47 +0900
committerGravatar corbot[bot] <corbot[bot]@users.noreply.github.com> 2019-02-17 14:51:47 +0000
commit362d7e96dce051a175e76cff2ce5bd314ad87c28 (patch)
tree6378eea048205cc10bd75319e49ad819c0a96431 /plugin
parent643dfd7419b20297002c53cf18ed0470c56f9813 (diff)
downloadcoredns-362d7e96dce051a175e76cff2ce5bd314ad87c28.tar.gz
coredns-362d7e96dce051a175e76cff2ce5bd314ad87c28.tar.zst
coredns-362d7e96dce051a175e76cff2ce5bd314ad87c28.zip
plugin/auto: Reload zones every one minute (#2516)
Automatically submitted.
Diffstat (limited to 'plugin')
-rw-r--r--plugin/auto/README.md10
-rw-r--r--plugin/auto/setup.go21
-rw-r--r--plugin/auto/setup_test.go59
3 files changed, 66 insertions, 24 deletions
diff --git a/plugin/auto/README.md b/plugin/auto/README.md
index 3101366b7..ea9ee9964 100644
--- a/plugin/auto/README.md
+++ b/plugin/auto/README.md
@@ -29,10 +29,12 @@ are used.
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
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
- CoreDNS should scan the directory; the default is every 60 seconds. This value is in seconds.
- The minimum value is 1 second.
-* `reload` interval to perform reload of zone if SOA version changes. Default is one minute.
+ name `db.example.com`, the extracted origin will be `example.com`.
+ **TIMEOUT** is deprecated and will be removed in a subsequent version.
+ `reload` will be used, if not defined
+ (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
and reloads zone when serial changes.
* `no_reload` deprecated. Sets reload to 0.
diff --git a/plugin/auto/setup.go b/plugin/auto/setup.go
index 62a4da870..22fac7e8e 100644
--- a/plugin/auto/setup.go
+++ b/plugin/auto/setup.go
@@ -77,9 +77,15 @@ func setup(c *caddy.Controller) error {
}
func autoParse(c *caddy.Controller) (Auto, error) {
+ nilInterval := -1 * time.Second
var a = Auto{
- loader: loader{template: "${1}", re: regexp.MustCompile(`db\.(.*)`), duration: 60 * time.Second},
- Zones: &Zones{},
+ loader: loader{
+ template: "${1}",
+ re: regexp.MustCompile(`db\.(.*)`),
+ ReloadInterval: nilInterval,
+ duration: nilInterval,
+ },
+ Zones: &Zones{},
}
config := dnsserver.GetConfig(c)
@@ -141,6 +147,7 @@ func autoParse(c *caddy.Controller) (Auto, error) {
if 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
}
@@ -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
}
diff --git a/plugin/auto/setup_test.go b/plugin/auto/setup_test.go
index 9754551d2..bc6b94f37 100644
--- a/plugin/auto/setup_test.go
+++ b/plugin/auto/setup_test.go
@@ -2,50 +2,67 @@ package auto
import (
"testing"
+ "time"
"github.com/mholt/caddy"
)
func TestAutoParse(t *testing.T) {
tests := []struct {
- inputFileRules string
- shouldErr bool
- expectedDirectory string
- expectedTempl string
- expectedRe string
- expectedTo []string
+ inputFileRules string
+ shouldErr bool
+ expectedDirectory string
+ expectedTempl string
+ expectedRe string
+ expectedReloadInterval time.Duration
+ expectedDuration time.Duration
+ expectedTo []string
}{
{
`auto example.org {
directory /tmp
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 {
directory /tmp
}`,
- false, "/tmp", "${1}", `db\.(.*)`, nil,
+ false, "/tmp", "${1}", `db\.(.*)`, 60 * time.Second, 60 * time.Second, nil,
},
{
`auto {
directory /tmp
no_reload
}`,
- false, "/tmp", "${1}", `db\.(.*)`, nil,
+ false, "/tmp", "${1}", `db\.(.*)`, 0 * time.Second, 0 * time.Second, nil,
},
{
`auto {
directory /tmp (.*) bliep
}`,
- false, "/tmp", "bliep", `(.*)`, nil,
+ false, "/tmp", "bliep", `(.*)`, 60 * time.Second, 60 * time.Second, nil,
},
{
`auto {
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 {
@@ -54,44 +71,44 @@ func TestAutoParse(t *testing.T) {
transfer to 127.0.0.2
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
{
`auto example.org {
directory
}`,
- true, "", "${1}", `db\.(.*)`, nil,
+ true, "", "${1}", `db\.(.*)`, 60 * time.Second, 60 * time.Second, nil,
},
{
`auto example.org {
directory /tmp * {1}
}`,
- true, "", "${1}", ``, nil,
+ true, "", "${1}", ``, 60 * time.Second, 60 * time.Second, nil,
},
{
`auto example.org {
directory /tmp * {1} aa
}`,
- true, "", "${1}", ``, nil,
+ true, "", "${1}", ``, 60 * time.Second, 60 * time.Second, nil,
},
{
`auto example.org {
directory /tmp .* {1}
}`,
- true, "", "${1}", ``, nil,
+ true, "", "${1}", ``, 60 * time.Second, 60 * time.Second, nil,
},
{
`auto example.org {
directory /tmp .* {1}
}`,
- true, "", "${1}", ``, nil,
+ true, "", "${1}", ``, 60 * time.Second, 60 * time.Second, nil,
},
{
`auto example.org {
directory /tmp .* {1}
}`,
- true, "", "${1}", ``, nil,
+ true, "", "${1}", ``, 60 * time.Second, 60 * time.Second, nil,
},
}
@@ -113,6 +130,12 @@ func TestAutoParse(t *testing.T) {
if a.loader.re.String() != test.expectedRe {
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 {
for j, got := range a.loader.transferTo {
if got != test.expectedTo[j] {