plugin/auto: Reload zones every one minute (#2516)
Automatically submitted.
This commit is contained in:
parent
643dfd7419
commit
362d7e96dc
3 changed files with 66 additions and 24 deletions
|
@ -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.
|
||||
|
|
|
@ -77,8 +77,14 @@ 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},
|
||||
loader: loader{
|
||||
template: "${1}",
|
||||
re: regexp.MustCompile(`db\.(.*)`),
|
||||
ReloadInterval: nilInterval,
|
||||
duration: nilInterval,
|
||||
},
|
||||
Zones: &Zones{},
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package auto
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mholt/caddy"
|
||||
)
|
||||
|
@ -13,6 +14,8 @@ func TestAutoParse(t *testing.T) {
|
|||
expectedDirectory string
|
||||
expectedTempl string
|
||||
expectedRe string
|
||||
expectedReloadInterval time.Duration
|
||||
expectedDuration time.Duration
|
||||
expectedTo []string
|
||||
}{
|
||||
{
|
||||
|
@ -20,32 +23,46 @@ func TestAutoParse(t *testing.T) {
|
|||
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] {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue