aboutsummaryrefslogtreecommitdiff
path: root/plugin/reload/reload.go
diff options
context:
space:
mode:
authorGravatar Francois Tur <ftur@infoblox.com> 2018-02-02 13:15:56 -0500
committerGravatar John Belamaric <jbelamaric@infoblox.com> 2018-02-02 13:15:56 -0500
commit244002477231ac5f1b92f415bee5a53d04fc33cc (patch)
tree42f58f33d6bc0e1ddece37a1f9c4e2775e005d41 /plugin/reload/reload.go
parent3fb07161b74b05fbea6e8f19cd4071fda8402480 (diff)
downloadcoredns-244002477231ac5f1b92f415bee5a53d04fc33cc.tar.gz
coredns-244002477231ac5f1b92f415bee5a53d04fc33cc.tar.zst
coredns-244002477231ac5f1b92f415bee5a53d04fc33cc.zip
Plugin/RELOAD - Tune usage of var global, add limit to options (#1457)
* tune usage of var global, add limit to options * update readme for minimal values * useless change to quick-off codecov * fix msgs for min values and tune the flag for end of reload usage, with a 'maybe' option * adding UT for min values, adding MD5 of corefile on the log
Diffstat (limited to 'plugin/reload/reload.go')
-rw-r--r--plugin/reload/reload.go33
1 files changed, 22 insertions, 11 deletions
diff --git a/plugin/reload/reload.go b/plugin/reload/reload.go
index e469b4526..e7031455f 100644
--- a/plugin/reload/reload.go
+++ b/plugin/reload/reload.go
@@ -9,12 +9,15 @@ import (
)
// reload periodically checks if the Corefile has changed, and reloads if so
+const (
+ unused = 0
+ maybeUsed = 1
+ used = 2
+)
type reload struct {
- instance *caddy.Instance
interval time.Duration
- sum [md5.Size]byte
- stopped bool
+ usage int
quit chan bool
}
@@ -26,13 +29,14 @@ func hook(event caddy.EventName, info interface{}) error {
// if reload is removed from the Corefile, then the hook
// is still registered but setup is never called again
// so we need a flag to tell us not to reload
- if r.stopped {
+ if r.usage == unused {
return nil
}
// this should be an instance. ok to panic if not
- r.instance = info.(*caddy.Instance)
- r.sum = md5.Sum(r.instance.Caddyfile().Body())
+ instance := info.(*caddy.Instance)
+ md5sum := md5.Sum(instance.Caddyfile().Body())
+ log.Printf("[INFO] Running configuration MD5 = %x\n", md5sum)
go func() {
tick := time.NewTicker(r.interval)
@@ -40,19 +44,26 @@ func hook(event caddy.EventName, info interface{}) error {
for {
select {
case <-tick.C:
- corefile, err := caddy.LoadCaddyfile(r.instance.Caddyfile().ServerType())
+ corefile, err := caddy.LoadCaddyfile(instance.Caddyfile().ServerType())
if err != nil {
continue
}
s := md5.Sum(corefile.Body())
- if s != r.sum {
- _, err := r.instance.Restart(corefile)
+ if s != md5sum {
+ // Let not try to restart with the same file, even though it is wrong.
+ md5sum = s
+ // now lets consider that plugin will not be reload, unless appear in next config file
+ // change status iof usage will be reset in setup if the plugin appears in config file
+ r.usage = maybeUsed
+ _, err := instance.Restart(corefile)
if err != nil {
log.Printf("[ERROR] Corefile changed but reload failed: %s\n", err)
continue
}
- // we are done, this hook gets called again with new instance
- r.stopped = true
+ // we are done, if the plugin was not set used, then it is not.
+ if r.usage == maybeUsed {
+ r.usage = unused
+ }
return
}
case <-r.quit: