You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pkg/logs/logs.go
+46Lines changed: 46 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7,13 +7,15 @@ import (
7
7
"log/slog"
8
8
"strings"
9
9
10
+
"github.com/go-logr/logr"
10
11
"github.com/spf13/pflag"
11
12
"k8s.io/apimachinery/pkg/util/runtime"
12
13
"k8s.io/apimachinery/pkg/util/sets"
13
14
"k8s.io/component-base/featuregate"
14
15
"k8s.io/component-base/logs"
15
16
logsapi "k8s.io/component-base/logs/api/v1"
16
17
_ "k8s.io/component-base/logs/json/register"
18
+
"k8s.io/klog/v2"
17
19
)
18
20
19
21
// venafi-kubernetes-agent follows [Kubernetes Logging Conventions] and writes
@@ -55,6 +57,21 @@ const (
55
57
Info=0
56
58
Debug=1
57
59
Trace=2
60
+
61
+
// Suppress the following logged warning:
62
+
// > W1119 13:54:32.103779 119328 reflector.go:561] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:243: failed to list route.openshift.io/v1, Resource=routes: the server could not find the requested resource
63
+
//
64
+
// Why? Because venafi-kubernetes-agent is expected to run in environments
65
+
// where some of the DataGatherer resources are not yet installed.
66
+
// If the resource is installed after venafi-kubernetes-agent starts, it
67
+
// will begin collecting that resource.
68
+
// If the resource is uninstalled after venafi-kubernetes-agent starts, it
69
+
// will stop collecting that resource.
70
+
// But if an API resource is not installed, the client-go reflector will
71
+
// return an error **and** print a warning.
72
+
// The error is already handled and logged in `k8s/dynamic.go`, so the
73
+
// warning is redundant and causes unnecessary distraction to the user.
74
+
FilteredMessageReflectorFailedToList="failed to list"
58
75
)
59
76
60
77
funcinit() {
@@ -131,6 +148,22 @@ func Initialize() error {
131
148
// to the global log logger. It can be removed when this is fixed upstream
132
149
// in vcert: https://github.com/Venafi/vcert/pull/512
133
150
vcertLog.SetPrefix("")
151
+
152
+
// Set up filtering of distracting client-go logs.
153
+
l:=klog.Background()
154
+
ls:=&filteringLogSink{
155
+
LogSink: l.GetSink(),
156
+
}
157
+
// This CallDepth is chosen by trial and error so that the logged line
158
+
// numbers match the site of the `log.Info` in the code.
159
+
// TODO(wallrj): Figure out how to automatically set the right call depth.
160
+
// TODO(wallrj): This CallDepth is not correct for client-go logs, e.g.
0 commit comments