Skip to content

Commit ee2db67

Browse files
authored
chore: config reload (#348)
1 parent 454ffbf commit ee2db67

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

cmd/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"flag"
21+
"github.com/fsnotify/fsnotify"
2122
"os"
2223

2324
"github.com/elliotchance/pie/v2"
@@ -280,6 +281,15 @@ func main() {
280281
Plane(featuretypes.PlaneKcp).
281282
Build(ctx)
282283

284+
go func() {
285+
err := cfg.Watch(ctx.Done(), func(_ fsnotify.Event) {
286+
cfg.Read()
287+
})
288+
if err != nil {
289+
rootLogger.Error(err, "Error from config watcher")
290+
}
291+
}()
292+
283293
if err := mgr.Start(ctx); err != nil {
284294
setupLog.Error(err, "problem running manager")
285295
os.Exit(1)

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (c *config) Read() {
117117
}
118118
}
119119

120-
func (c *config) Watch(stopCh chan struct{}, onConfigChange func(event fsnotify.Event)) error {
120+
func (c *config) Watch(stopCh <-chan struct{}, onConfigChange func(event fsnotify.Event)) error {
121121
state := &watchedState{}
122122

123123
// if nil provided, it won't ever be closed, aka watch stopped, make a stub instead

pkg/config/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Config interface {
1515
SourceEnv(fieldPath string, envVarPrefix string)
1616
Sensitive(fieldPath string)
1717
Read()
18-
Watch(stopCh chan struct{}, onConfigChange func(event fsnotify.Event)) error
18+
Watch(stopCh <-chan struct{}, onConfigChange func(event fsnotify.Event)) error
1919
Bind(fieldPath string, obj any)
2020
Json() string
2121
PrintJson() string

0 commit comments

Comments
 (0)