From 3e5b152a81082da51d72c37bf00b3ae2cede5a1d Mon Sep 17 00:00:00 2001 From: Maxim Muzafarov Date: Tue, 30 Jul 2024 14:57:50 +0100 Subject: [PATCH] Recreate watcher if the file was renamed --- pkg/certwatcher/certwatcher.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/certwatcher/certwatcher.go b/pkg/certwatcher/certwatcher.go index 2b9b60d8d7..1e617d665f 100644 --- a/pkg/certwatcher/certwatcher.go +++ b/pkg/certwatcher/certwatcher.go @@ -173,14 +173,14 @@ func (cw *CertWatcher) ReadCertificate() error { func (cw *CertWatcher) handleEvent(event fsnotify.Event) { // Only care about events which may modify the contents of the file. - if !(isWrite(event) || isRemove(event) || isCreate(event)) { + if !(isWrite(event) || isRemove(event) || isCreate(event) || isRename(event)) { return } log.V(1).Info("certificate event", "event", event) // If the file was removed, re-add the watch. - if isRemove(event) { + if isRemove(event) || isRename(event) { if err := cw.watcher.Add(event.Name); err != nil { log.Error(err, "error re-watching file") } @@ -202,3 +202,7 @@ func isCreate(event fsnotify.Event) bool { func isRemove(event fsnotify.Event) bool { return event.Op.Has(fsnotify.Remove) } + +func isRename(event fsnotify.Event) bool { + return event.Op.Has(fsnotify.Rename) +}