Skip to content

Commit

Permalink
cleanup: refine file watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhangx authored and k8s-infra-cherrypick-robot committed Nov 14, 2024
1 parent 5734acc commit 1b887f3
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions pkg/filewatcher/filewatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ func WatchFileForChanges(fileToWatch string) error {

// This starts only one occurrence of the file watcher, which watches the file, fileToWatch.
watchCertificateFileOnce.Do(func() {
klog.Infof("Starting the file change watcher on file, %s", fileToWatch)
klog.V(2).Infof("Starting the file change watcher on file, %s", fileToWatch)

// Update the file path to watch in case this is a symlink
fileToWatch, err = filepath.EvalSymlinks(fileToWatch)
if err != nil {
return
}
klog.Infof("Watching file, %s", fileToWatch)
klog.V(2).Infof("Watching file, %s", fileToWatch)

// Start the file watcher to monitor file changes
go func() {
Expand All @@ -63,7 +63,7 @@ func checkForFileChanges(path string) error {
select {
case event, ok := <-watcher.Events:
if ok && (event.Has(fsnotify.Write) || event.Has(fsnotify.Chmod) || event.Has(fsnotify.Remove)) {
klog.Infof("file, %s, was modified, exiting...", event.Name)
klog.V(2).Infof("file, %s, was modified, exiting...", event.Name)
os.Exit(0)
}
case err, ok := <-watcher.Errors:
Expand All @@ -74,10 +74,5 @@ func checkForFileChanges(path string) error {
}
}()

err = watcher.Add(path)
if err != nil {
return err
}

return nil
return watcher.Add(path)
}

0 comments on commit 1b887f3

Please sign in to comment.