Skip to content

Commit

Permalink
chore: config reload (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilos77 authored Jul 12, 2024
1 parent 454ffbf commit ee2db67
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"flag"
"github.com/fsnotify/fsnotify"
"os"

"github.com/elliotchance/pie/v2"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ee2db67

Please sign in to comment.