Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: refine file watcher logging #2631

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading