Skip to content

Commit 3e5b152

Browse files
authored
Recreate watcher if the file was renamed
1 parent 6785442 commit 3e5b152

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/certwatcher/certwatcher.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ func (cw *CertWatcher) ReadCertificate() error {
173173

174174
func (cw *CertWatcher) handleEvent(event fsnotify.Event) {
175175
// Only care about events which may modify the contents of the file.
176-
if !(isWrite(event) || isRemove(event) || isCreate(event)) {
176+
if !(isWrite(event) || isRemove(event) || isCreate(event) || isRename(event)) {
177177
return
178178
}
179179

180180
log.V(1).Info("certificate event", "event", event)
181181

182182
// If the file was removed, re-add the watch.
183-
if isRemove(event) {
183+
if isRemove(event) || isRename(event) {
184184
if err := cw.watcher.Add(event.Name); err != nil {
185185
log.Error(err, "error re-watching file")
186186
}
@@ -202,3 +202,7 @@ func isCreate(event fsnotify.Event) bool {
202202
func isRemove(event fsnotify.Event) bool {
203203
return event.Op.Has(fsnotify.Remove)
204204
}
205+
206+
func isRename(event fsnotify.Event) bool {
207+
return event.Op.Has(fsnotify.Rename)
208+
}

0 commit comments

Comments
 (0)