Fix logspam in leaderelection controller.

If the reconcileElectionStep function returns `noRequeue, nil`, it causes log
spam from apiserver.  This is because HandleErrorWithContext regardless of
error value.  Skip logging if error is nil.

Also, tag the log message with the involved lease object name.

```
...
{"ts":1773796037662.8264,"logger":"UnhandledError","caller":"leaderelection/leaderelection_controller.go:169","msg":"Failed to reconcile election step"}
{"ts":1773796038472.465,"logger":"UnhandledError","caller":"leaderelection/leaderelection_controller.go:169","msg":"Failed to reconcile election step"}
...
```
This commit is contained in:
Abhijit Hoskeri
2026-03-17 18:05:20 -07:00
parent 6175c54954
commit c07f3ebbde

View File

@@ -166,7 +166,9 @@ func (c *Controller) processNextElectionItem(ctx context.Context) bool {
}
intervalForRequeue, err := c.reconcileElectionStep(ctx, key)
utilruntime.HandleErrorWithContext(ctx, err, "Failed to reconcile election step")
if err != nil { // HandleErrorWithContext logs regardless of error value, filter out nil err.
utilruntime.HandleErrorWithContext(ctx, err, "Failed to reconcile election step", "key", key)
}
if intervalForRequeue != noRequeue {
defer c.queue.AddAfter(key, intervalForRequeue)
}