Skip to content

Fix controller-runtime logger to suppress SetLogger warning - #461

Open
shashankvarma499 wants to merge 1 commit into
crossplane-contrib:masterfrom
shashankvarma499:fix/ctrl-logger-setlogger
Open

shashankvarma499 wants to merge 1 commit into
crossplane-contrib:masterfrom
shashankvarma499:fix/ctrl-logger-setlogger

Conversation

@shashankvarma499

Copy link
Copy Markdown

Description of your changes

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 called ctrl.SetLogger in debug mode, so this
warning fired continuously in production, polluting the logs with a stack trace
per reconcile.

Set the controller-runtime logger unconditionally: use the zap logger in debug
mode and a discard logger otherwise. This keeps the previous quiet behaviour in
non-debug mode while still satisfying controller-runtime's expectation and
eliminating the per-reconcile warning.

Fixes #342

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

  • go build ./... passes.
  • go vet ./cmd/provider/... passes.
  • go test ./... -count=1 passes.
  • The change is confined to cmd/provider/main.go (the entrypoint), which has no
    unit-test surface; behaviour is verified by running the provider and observing
    the warning is gone.

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 crossplane-contrib#342

Signed-off-by: Shashank Varma <324153016+shashankvarma499@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[controller-runtime] log.SetLogger(...) was never called; logs will not be displayed.

1 participant