fix: suppress kubedog context canceled errors

- Use klog.Background() to suppress INFO level warnings
- Filter context canceled and related errors during normal shutdown
- Simplified implementation without modifying runtime.ErrorHandlers

This is a cleaner and more idiomatic solution that:
resolves the lint error:
- Cannot reassign variables from other packages (reassign)
- Remove unused shouldFilter function (unused)

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2026-03-04 13:39:59 +08:00
parent 615e8132ee
commit 4950e4239a
2 changed files with 19 additions and 0 deletions

17
pkg/kubedog/init.go Normal file
View File

@ -0,0 +1,17 @@
package kubedog
import (
"sync"
"k8s.io/klog/v2"
)
var (
errorHandlersInitOnce sync.Once
)
func initErrorHandlers() {
errorHandlersInitOnce.Do(func() {
klog.SetLogger(klog.Background())
})
}

View File

@ -66,6 +66,8 @@ type TrackerConfig struct {
}
func NewTracker(config *TrackerConfig) (*Tracker, error) {
initErrorHandlers()
logger := config.Logger
if logger == nil {
logger = zap.NewNop().Sugar()