mirror of
https://github.com/project-zot/zot.git
synced 2026-06-15 20:07:55 +08:00
lint: Move out config reloader context from controller struct
Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
committed by
Ramkumar Chinchani
parent
353b0c6034
commit
be910cf01c
@@ -72,7 +72,7 @@ func TestTLSWithAuth(t *testing.T) {
|
||||
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||
go func() {
|
||||
// this blocks
|
||||
if err := ctlr.Run(); err != nil {
|
||||
if err := ctlr.Run(context.Background()); err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
@@ -164,7 +164,7 @@ func TestTLSWithoutAuth(t *testing.T) {
|
||||
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||
go func() {
|
||||
// this blocks
|
||||
if err := ctlr.Run(); err != nil {
|
||||
if err := ctlr.Run(context.Background()); err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
@@ -227,7 +227,7 @@ func TestTLSWithoutAuth(t *testing.T) {
|
||||
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||
go func() {
|
||||
// this blocks
|
||||
if err := ctlr.Run(); err != nil {
|
||||
if err := ctlr.Run(context.Background()); err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
@@ -285,7 +285,7 @@ func TestTLSBadCerts(t *testing.T) {
|
||||
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||
go func() {
|
||||
// this blocks
|
||||
if err := ctlr.Run(); err != nil {
|
||||
if err := ctlr.Run(context.Background()); err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ func TestServerCVEResponse(t *testing.T) {
|
||||
|
||||
go func(controller *api.Controller) {
|
||||
// this blocks
|
||||
if err := controller.Run(); err != nil {
|
||||
if err := controller.Run(context.Background()); err != nil {
|
||||
return
|
||||
}
|
||||
}(ctlr)
|
||||
|
||||
@@ -294,7 +294,7 @@ func TestServerResponse(t *testing.T) {
|
||||
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||
go func(controller *api.Controller) {
|
||||
// this blocks
|
||||
if err := controller.Run(); err != nil {
|
||||
if err := controller.Run(context.Background()); err != nil {
|
||||
return
|
||||
}
|
||||
}(ctlr)
|
||||
|
||||
+6
-3
@@ -44,14 +44,17 @@ func newServeCmd(conf *config.Config) *cobra.Command {
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
// config reloader
|
||||
hotReloader, err := NewHotReloader(ctlr, args[0])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
hotReloader.Start()
|
||||
/* context used to cancel go routines so that
|
||||
we can change their config on the fly (restart routines with different config) */
|
||||
reloaderCtx := hotReloader.Start()
|
||||
|
||||
if err := ctlr.Run(); err != nil {
|
||||
if err := ctlr.Run(reloaderCtx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
},
|
||||
@@ -100,7 +103,7 @@ func newScrubCmd(conf *config.Config) *cobra.Command {
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Metrics = monitoring.NewMetricsServer(false, ctlr.Log)
|
||||
|
||||
if err := ctlr.InitImageStore(); err != nil {
|
||||
if err := ctlr.InitImageStore(context.Background()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -409,7 +409,7 @@ func TestScrub(t *testing.T) {
|
||||
controller.Config.Storage.RootDirectory = dir
|
||||
go func(controller *api.Controller) {
|
||||
// this blocks
|
||||
if err := controller.Run(); err != nil {
|
||||
if err := controller.Run(context.Background()); err != nil {
|
||||
return
|
||||
}
|
||||
}(controller)
|
||||
|
||||
Reference in New Issue
Block a user