Skip to content

Commit fafc280

Browse files
committed
Send leader election messages to the global logger
1 parent 41037bc commit fafc280

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cmd/postgres-operator/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"k8s.io/apimachinery/pkg/util/validation"
2222
"k8s.io/client-go/rest"
23+
"k8s.io/klog/v2"
2324
"sigs.k8s.io/controller-runtime/pkg/healthz"
2425
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
2526

@@ -88,14 +89,18 @@ func initLogging() {
8889

8990
global := logging.FromContext(context.Background())
9091
runtime.SetLogger(global)
92+
93+
// [k8s.io/client-go/tools/leaderelection] logs to the global [klog] instance.
94+
// - https://github.com/kubernetes-sigs/controller-runtime/issues/2656
95+
klog.SetLoggerWithOptions(global, klog.ContextualLogger(true))
9196
}
9297

9398
//+kubebuilder:rbac:groups="coordination.k8s.io",resources="leases",verbs={get,create,update,watch}
9499
//+kubebuilder:rbac:groups="authentication.k8s.io",resources="tokenreviews",verbs={create}
95100
//+kubebuilder:rbac:groups="authorization.k8s.io",resources="subjectaccessreviews",verbs={create}
96101

97102
func initManager(ctx context.Context) (runtime.Options, error) {
98-
log := logging.FromContext(ctx)
103+
log := logging.FromContext(ctx).WithName("manager")
99104

100105
options := runtime.Options{}
101106
options.Cache.SyncPeriod = initialize.Pointer(time.Hour)

0 commit comments

Comments
 (0)