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
|
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.
|
||||||
|
|
|
@ -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) {
|
||||||
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) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
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) {
|
||||||
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] {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue