File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package kubernetes
2+
3+ import (
4+ clog "github.com/coredns/coredns/plugin/pkg/log"
5+
6+ "github.com/go-logr/logr"
7+ )
8+
9+ // loggerAdapter is a simple wrapper around CoreDNS plugin logger made to implement logr.LogSink interface, which is used
10+ // as part of klog library for logging in Kubernetes client. By using this adapter CoreDNS is able to log messages/errors from
11+ // kubernetes client in a CoreDNS logging format
12+ type loggerAdapter struct {
13+ clog.P
14+ }
15+
16+ func (l * loggerAdapter ) Init (_ logr.RuntimeInfo ) {
17+ }
18+
19+ func (l * loggerAdapter ) Enabled (_ int ) bool {
20+ // verbosity is controlled inside klog library, we do not need to do anything here
21+ return true
22+ }
23+
24+ func (l * loggerAdapter ) Info (_ int , msg string , _ ... interface {}) {
25+ l .P .Info (msg )
26+ }
27+
28+ func (l * loggerAdapter ) Error (_ error , msg string , _ ... interface {}) {
29+ l .P .Error (msg )
30+ }
31+
32+ func (l * loggerAdapter ) WithValues (_ ... interface {}) logr.LogSink {
33+ return l
34+ }
35+
36+ func (l * loggerAdapter ) WithName (_ string ) logr.LogSink {
37+ return l
38+ }
Original file line number Diff line number Diff line change 44 "context"
55 "errors"
66 "fmt"
7- "os"
87 "strconv"
98 "strings"
109
@@ -15,6 +14,7 @@ import (
1514 clog "github.com/coredns/coredns/plugin/pkg/log"
1615 "github.com/coredns/coredns/plugin/pkg/upstream"
1716
17+ "github.com/go-logr/logr"
1818 "github.com/miekg/dns"
1919 meta "k8s.io/apimachinery/pkg/apis/meta/v1"
2020 _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // pull this in here, because we want it excluded if plugin.cfg doesn't have k8s
@@ -32,7 +32,7 @@ func init() { plugin.Register(pluginName, setup) }
3232
3333func setup (c * caddy.Controller ) error {
3434 // Do not call klog.InitFlags(nil) here. It will cause reload to panic.
35- klog .SetOutput ( os . Stdout )
35+ klog .SetLogger ( logr . New ( & loggerAdapter { log }) )
3636
3737 k , err := kubernetesParse (c )
3838 if err != nil {
You can’t perform that action at this time.
0 commit comments