Skip to content

Commit

Permalink
Recreate watcher if the file was renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
m-messiah authored Jul 30, 2024
1 parent 6785442 commit 3e5b152
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/certwatcher/certwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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)
}

0 comments on commit 3e5b152

Please sign in to comment.