mirror of
https://github.com/coredns/coredns.git
synced 2026-03-11 00:03:10 -04:00
plugin/reload: Allow disabling jitter with 0s (#7896)
This PR fixes #7894 by allowing reload 2s 0s as documented. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@@ -52,16 +52,19 @@ func setup(c *caddy.Controller) error {
|
||||
}
|
||||
j = d
|
||||
}
|
||||
if j < minJitter {
|
||||
return plugin.Error("reload", fmt.Errorf("jitter value must be greater or equal to %v", minJitter))
|
||||
|
||||
if j != 0 && j < minJitter {
|
||||
return plugin.Error("reload", fmt.Errorf("jitter value must be 0 or greater or equal to %v", minJitter))
|
||||
}
|
||||
|
||||
if j > i/2 {
|
||||
if j > 0 && j > i/2 {
|
||||
j = i / 2
|
||||
}
|
||||
|
||||
jitter := time.Duration(rand.Int63n(j.Nanoseconds()) - (j.Nanoseconds() / 2)) // #nosec G404 -- non-cryptographic jitter.
|
||||
i = i + jitter
|
||||
if j > 0 {
|
||||
jitter := time.Duration(rand.Int63n(j.Nanoseconds()) - (j.Nanoseconds() / 2)) // #nosec G404 -- non-cryptographic jitter.
|
||||
i = i + jitter
|
||||
}
|
||||
|
||||
// prepare info for next onInstanceStartup event
|
||||
r.setInterval(i)
|
||||
|
||||
@@ -22,6 +22,11 @@ func TestSetupReload(t *testing.T) {
|
||||
t.Fatalf("Expected no errors, but got: %v", err)
|
||||
}
|
||||
|
||||
c = caddy.NewTestController("dns", `reload 2s 0s`)
|
||||
if err := setup(c); err != nil {
|
||||
t.Fatalf("Expected no errors, but got: %v", err)
|
||||
}
|
||||
|
||||
c = caddy.NewTestController("dns", `reload foo`)
|
||||
if err := setup(c); err == nil {
|
||||
t.Fatalf("Expected errors, but got: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user