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>

Kubernetes-commit: 17ad4b39f8b6b299d20fb94f99083ea84083b6b2
This commit is contained in:
Sohan Kunkerkar 2024-07-23 10:55:16 -04:00 committed by Kubernetes Publisher
parent 932b2589d5
commit fed8dfe736
1 changed files with 2 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/x509" "crypto/x509"
"errors"
"fmt" "fmt"
"os" "os"
"sync/atomic" "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) { if !e.Has(fsnotify.Remove) && !e.Has(fsnotify.Rename) {
return nil 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) 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 { if err := w.Add(c.filename); err != nil {