lint: Move out config reloader context from controller struct

Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
Petu Eusebiu
2022-03-24 14:49:51 +02:00
committed by Ramkumar Chinchani
parent 353b0c6034
commit be910cf01c
17 changed files with 91 additions and 84 deletions
+12 -2
View File
@@ -1,6 +1,8 @@
package cli
import (
"context"
"github.com/fsnotify/fsnotify"
"github.com/rs/zerolog/log"
"zotregistry.io/zot/pkg/api"
@@ -29,8 +31,10 @@ func NewHotReloader(ctlr *api.Controller, filePath string) (*HotReloader, error)
return hotReloader, nil
}
func (hr *HotReloader) Start() {
func (hr *HotReloader) Start() context.Context {
done := make(chan bool)
reloadCtx, cancelOnReloadFunc := context.WithCancel(context.Background())
// run watcher
go func() {
defer hr.watcher.Close()
@@ -51,8 +55,12 @@ func (hr *HotReloader) Start() {
continue
}
// if valid config then reload
cancelOnReloadFunc()
hr.ctlr.LoadNewConfig(newConfig)
// create new context
reloadCtx, cancelOnReloadFunc = context.WithCancel(context.Background())
hr.ctlr.LoadNewConfig(reloadCtx, newConfig)
}
// watch for errors
case err := <-hr.watcher.Errors:
@@ -69,4 +77,6 @@ func (hr *HotReloader) Start() {
<-done
}()
return reloadCtx
}