Files
coredns/plugin/kubernetes/logger.go
Andrey Smirnov 604e1675cf fix: kubernetes plugin logging (#7727)
The plugin dropped the actual error message from the log, so the log
becomes completely useless.

Before:

```
[ERROR] plugin/kubernetes: error Failed to watch
```

After:

```
[ERROR] plugin/kubernetes: Failed to watch: failed to list *v1.Namespace: Get "https://10.96.0.1:443/api/v1/namespaces?limit=500&resourceVersion=0": tls: failed to parse certificate from server: x509: SAN dNSName is malformed
```

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
2025-11-27 19:46:04 +02:00

39 lines
966 B
Go

package kubernetes
import (
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/go-logr/logr"
)
// loggerAdapter is a simple wrapper around CoreDNS plugin logger made to implement logr.LogSink interface, which is used
// as part of klog library for logging in Kubernetes client. By using this adapter CoreDNS is able to log messages/errors from
// kubernetes client in a CoreDNS logging format
type loggerAdapter struct {
clog.P
}
func (l *loggerAdapter) Init(_ logr.RuntimeInfo) {
}
func (l *loggerAdapter) Enabled(_ int) bool {
// verbosity is controlled inside klog library, we do not need to do anything here
return true
}
func (l *loggerAdapter) Info(_ int, msg string, _ ...any) {
l.P.Info(msg)
}
func (l *loggerAdapter) Error(err error, msg string, _ ...any) {
l.Errorf("%s: %s", msg, err)
}
func (l *loggerAdapter) WithValues(_ ...any) logr.LogSink {
return l
}
func (l *loggerAdapter) WithName(_ string) logr.LogSink {
return l
}