dynamiccertificates: denoise Kubelet logs by skipping removal of non-existent file watchers

This commit updates the DynamicFileCAContent controller to skip the removal
of non-existent file watchers. Previously, the controller attempted to remove
a file watch even if it didn't exist, which resulted in a flood of error messages
being logged in the Kubelet logs.

Signed-off-by: Sohan Kunkerkar <sohank2602@gmail.com>
This commit is contained in:
Sohan Kunkerkar 2024-07-23 10:55:16 -04:00
parent 1854839ff0
commit 17ad4b39f8

View File

@ -20,6 +20,7 @@ import (
"bytes"
"context"
"crypto/x509"
"errors"
"fmt"
"os"
"sync/atomic"
@ -210,7 +211,7 @@ func (c *DynamicFileCAContent) handleWatchEvent(e fsnotify.Event, w *fsnotify.Wa
if !e.Has(fsnotify.Remove) && !e.Has(fsnotify.Rename) {
return nil
}
if err := w.Remove(c.filename); err != nil {
if err := w.Remove(c.filename); err != nil && !errors.Is(err, fsnotify.ErrNonExistentWatch) {
klog.InfoS("Failed to remove file watch, it may have been deleted", "file", c.filename, "err", err)
}
if err := w.Add(c.filename); err != nil {