From ee2db67febede6c639595066e731f3545925749c Mon Sep 17 00:00:00 2001 From: Milos Tomic <59831542+tmilos77@users.noreply.github.com> Date: Fri, 12 Jul 2024 14:15:47 +0200 Subject: [PATCH] chore: config reload (#348) --- cmd/main.go | 10 ++++++++++ pkg/config/config.go | 2 +- pkg/config/types.go | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 049771a47..523a93d4d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -18,6 +18,7 @@ package main import ( "flag" + "github.com/fsnotify/fsnotify" "os" "github.com/elliotchance/pie/v2" @@ -280,6 +281,15 @@ func main() { Plane(featuretypes.PlaneKcp). Build(ctx) + go func() { + err := cfg.Watch(ctx.Done(), func(_ fsnotify.Event) { + cfg.Read() + }) + if err != nil { + rootLogger.Error(err, "Error from config watcher") + } + }() + if err := mgr.Start(ctx); err != nil { setupLog.Error(err, "problem running manager") os.Exit(1) diff --git a/pkg/config/config.go b/pkg/config/config.go index eb0be37e9..09b6f85a7 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -117,7 +117,7 @@ func (c *config) Read() { } } -func (c *config) Watch(stopCh chan struct{}, onConfigChange func(event fsnotify.Event)) error { +func (c *config) Watch(stopCh <-chan struct{}, onConfigChange func(event fsnotify.Event)) error { state := &watchedState{} // if nil provided, it won't ever be closed, aka watch stopped, make a stub instead diff --git a/pkg/config/types.go b/pkg/config/types.go index be23b57a6..46fae96eb 100644 --- a/pkg/config/types.go +++ b/pkg/config/types.go @@ -15,7 +15,7 @@ type Config interface { SourceEnv(fieldPath string, envVarPrefix string) Sensitive(fieldPath string) Read() - Watch(stopCh chan struct{}, onConfigChange func(event fsnotify.Event)) error + Watch(stopCh <-chan struct{}, onConfigChange func(event fsnotify.Event)) error Bind(fieldPath string, obj any) Json() string PrintJson() string