From 417fd82ea484d344d0bdaf7c4572056accaffd7a Mon Sep 17 00:00:00 2001 From: Shashank Varma <324153016+shashankvarma499@users.noreply.github.com> Date: Sun, 13 Sep 2026 16:39:16 +0000 Subject: [PATCH] Fix controller-runtime logger to suppress SetLogger warning controller-runtime v0.22.0 emits a "log.SetLogger(...) was never called" warning with a full stack trace on every reconcile when its root logger is left unset. The provider only set the logger in debug mode, so the warning fired continuously in production. Set the logger unconditionally: use the zap logger in debug mode and a discard logger otherwise, preserving the existing quiet behaviour while satisfying controller-runtime's expectation. Fixes #342 Signed-off-by: Shashank Varma <324153016+shashankvarma499@users.noreply.github.com> --- cmd/provider/main.go | 12 +++++++++--- go.mod | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/provider/main.go b/cmd/provider/main.go index 994f71c5..3ade5a9d 100644 --- a/cmd/provider/main.go +++ b/cmd/provider/main.go @@ -26,6 +26,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "github.com/alecthomas/kingpin/v2" + "github.com/go-logr/logr" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" clientgoscheme "k8s.io/client-go/kubernetes/scheme" ctrl "sigs.k8s.io/controller-runtime" @@ -62,11 +63,16 @@ func main() { zl := zap.New(zap.UseDevMode(*debug)) log := logging.NewLogrLogger(zl.WithName("provider-sql")) + + // controller-runtime leaves its root logger unset by default and emits a + // "log.SetLogger(...) was never called" warning (with a stack trace) on + // every reconcile when it is never set. It is also very verbose even at + // info level, so in non-debug mode we point it at a discard logger to keep + // the previous quiet behaviour while still satisfying controller-runtime. if *debug { - // The controller-runtime runs with a no-op logger by default. It is - // *very* verbose even at info level, so we only provide it a real - // logger when we're running in debug mode. ctrl.SetLogger(zl) + } else { + ctrl.SetLogger(logr.Discard()) } log.Debug("Starting", "sync-period", syncPeriod.String()) diff --git a/go.mod b/go.mod index 3dcc96e8..170d3fca 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/crossplane/crossplane-tools v0.0.0-20260719180100-659f1dc036c5 github.com/crossplane/crossplane/apis/v2 v2.4.0 github.com/crossplane/upjet/v2 v2.2.0 + github.com/go-logr/logr v1.4.4 github.com/go-sql-driver/mysql v1.10.0 github.com/google/go-cmp v0.7.0 github.com/lib/pq v1.12.3 @@ -42,7 +43,6 @@ require ( github.com/fatih/color v1.19.0 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/fxamacker/cbor/v2 v2.9.1 // indirect - github.com/go-logr/logr v1.4.4 // indirect github.com/go-logr/zapr v1.3.0 // indirect github.com/go-openapi/jsonpointer v1.0.0 // indirect github.com/go-openapi/jsonreference v1.0.0 // indirect