From 3bd1b23ce05449f3b4313f82ef9f9f163dd0cd52 Mon Sep 17 00:00:00 2001 From: Leoyzen Date: Sat, 28 Jun 2025 02:49:31 +0800 Subject: [PATCH] fix config hot-reload on k8s (#181) Co-authored-by: Leoyzen --- llama-swap.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/llama-swap.go b/llama-swap.go index 62b1eaf..f801ad7 100644 --- a/llama-swap.go +++ b/llama-swap.go @@ -145,7 +145,7 @@ func watchConfigFileWithReload(configPath string, reloadChan chan<- *proxy.Proxy return } // We only care about writes/creates to the specific config file - if event.Name == configPath && (event.Has(fsnotify.Write) || event.Has(fsnotify.Create)) { + if event.Name == configPath && (event.Has(fsnotify.Write) || event.Has(fsnotify.Create) || event.Has(fsnotify.Remove)) { // Reset or start the debounce timer if debounceTimer != nil { debounceTimer.Stop() @@ -176,6 +176,13 @@ func watchConfigFileWithReload(configPath string, reloadChan chan<- *proxy.Proxy newPM := proxy.New(newConfig) reloadChan <- newPM log.Println("Config reloaded successfully") + if (event.Has(fsnotify.Remove)) { + // re-add watcher + err = watcher.Add(configPath) + if err != nil { + log.Printf("Could not re-add watcher for %s: %s", configPath, err) + } + } }) } case err, ok := <-watcher.Errors: