karmada-io / karmada

Open, Multi-Cloud, Multi-Cluster Kubernetes Orchestration
https://karmada.io
Apache License 2.0
4.12k stars 807 forks source link

karmada-webhook: log.SetLogger(...) was never called; logs will not be displayed. #4868

Closed XiShanYongYe-Chang closed 5 days ago

XiShanYongYe-Chang commented 1 week ago

What would you like to be added:

When karmada-webhook is started, the following log will be prompted:

[controller-runtime] log.SetLogger(...) was never called; logs will not be displayed.
Detected at:
        >  goroutine 1038 [running]:
        >  runtime/debug.Stack()
        >       /usr/local/go/src/runtime/debug/stack.go:24 +0x5e
        >  sigs.k8s.io/controller-runtime/pkg/log.eventuallyFulfillRoot()
        >       /root/go/src/github.com/karmada-io/karmada/vendor/sigs.k8s.io/controller-runtime/pkg/log/log.go:60 +0xcd
        >  sigs.k8s.io/controller-runtime/pkg/log.(*delegatingLogSink).WithName(0xc0004041c0, {0x1b8759b, 0x9})
        >       /root/go/src/github.com/karmada-io/karmada/vendor/sigs.k8s.io/controller-runtime/pkg/log/deleg.go:147 +0x45
        >  github.com/go-logr/logr.Logger.WithName(...)
        >       /root/go/src/github.com/karmada-io/karmada/vendor/github.com/go-logr/logr/logr.go:336
        >  sigs.k8s.io/controller-runtime/pkg/webhook/admission.(*Webhook).getLogger.func1()
        >       /root/go/src/github.com/karmada-io/karmada/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/admission/webhook.go:182 +0x66
        >  sync.(*Once).doSlow(0x0?, 0xc0003e26e0?)
        >       /usr/local/go/src/sync/once.go:74 +0xbf
        >  sync.(*Once).Do(...)
        >       /usr/local/go/src/sync/once.go:65
        >  sigs.k8s.io/controller-runtime/pkg/webhook/admission.(*Webhook).getLogger(0xc0001fdc70, 0xc000233800?)
        >       /root/go/src/github.com/karmada-io/karmada/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/admission/webhook.go:180 +0x4d
        >  sigs.k8s.io/controller-runtime/pkg/webhook/admission.(*Webhook).ServeHTTP(0xc0001fdc70, {0x7f0dc8b04b40?, 0xc0002b9c20}, 0xc0005acf00)
        >       /root/go/src/github.com/karmada-io/karmada/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/admission/http.go:96 +0xbab
        >  sigs.k8s.io/controller-runtime/pkg/webhook/internal/metrics.InstrumentedHook.InstrumentHandlerInFlight.func1({0x7f0dc8b04b40, 0xc0002b9c20}, 0x1eb0000?)
        >       /root/go/src/github.com/karmada-io/karmada/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go:60 +0xcb
        >  net/http.HandlerFunc.ServeHTTP(0x1eb0010?, {0x7f0dc8b04b40?, 0xc0002b9c20?}, 0xc0004e58a0?)
        >       /usr/local/go/src/net/http/server.go:2136 +0x29
        >  github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerCounter.func1({0x1eb0010?, 0xc00017f0a0?}, 0xc0005acf00)
        >       /root/go/src/github.com/karmada-io/karmada/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go:147 +0xb6
        >  net/http.HandlerFunc.ServeHTTP(0x82ca46?, {0x1eb0010?, 0xc00017f0a0?}, 0x410aa5?)
        >       /usr/local/go/src/net/http/server.go:2136 +0x29
        >  github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerDuration.func2({0x1eb0010, 0xc00017f0a0}, 0xc0005acf00)
        >       /root/go/src/github.com/karmada-io/karmada/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go:109 +0xc2
        >  net/http.HandlerFunc.ServeHTTP(0x10?, {0x1eb0010?, 0xc00017f0a0?}, 0xc00057c56c?)
        >       /usr/local/go/src/net/http/server.go:2136 +0x29
        >  net/http.(*ServeMux).ServeHTTP(0x410aa5?, {0x1eb0010, 0xc00017f0a0}, 0xc0005acf00)
        >       /usr/local/go/src/net/http/server.go:2514 +0x142
        >  net/http.serverHandler.ServeHTTP({0x1ea8ba0?}, {0x1eb0010?, 0xc00017f0a0?}, 0x6?)
        >       /usr/local/go/src/net/http/server.go:2938 +0x8e
        >  net/http.(*conn).serve(0xc00050db00, {0x1ebd5f8, 0xc0004a2960})
        >       /usr/local/go/src/net/http/server.go:2009 +0x5f4
        >  created by net/http.(*Server).Serve in goroutine 128
        >       /usr/local/go/src/net/http/server.go:3086 +0x5cb

This log looks like a panic error in form (in fact, it is not). This will be confusing when searching the log. I hope it can be avoided.

Why is this needed:

XiShanYongYe-Chang commented 1 week ago

/help

karmada-bot commented 1 week ago

@XiShanYongYe-Chang: This request has been marked as needing help from a contributor.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed by commenting with the /remove-help command.

In response to [this](https://github.com/karmada-io/karmada/issues/4868): >/help Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
whitewindmills commented 1 week ago

I have never encountered such a log prompt, so I'd like to work on it, how to reproduct it?

XiShanYongYe-Chang commented 1 week ago

I have never encountered such a log prompt, so I'd like to work on it, how to reproduct it?

I'm using the code on the master branch, and after deploying using the hack/local-up-karmada.sh script, I'm getting this.

whitewindmills commented 1 week ago

:skull_and_crossbones: Failed to reproduce it. image

XiShanYongYe-Chang commented 1 week ago

Do you have any additional settings for the log?

whitewindmills commented 1 week ago

Do you have any additional settings for the log?

No, I followed your steps strictly.

XiShanYongYe-Chang commented 1 week ago

That's weird. Let me look into it.

liangyuanpeng commented 1 week ago

Want to reproduce it and get nothing, follow the below steps:

  1. git clone https://github.com/karmada-io/karmada
  2. cd karmada && hack/local-up-karmada.sh
  3. kubectl --kubeconfig ~/.kube/karmada.config logs -n karmada-system -l app=karmada-webhook
XiShanYongYe-Chang commented 1 week ago

image

XiShanYongYe-Chang commented 1 week ago

Redeployed, it's still show up.

whitewindmills commented 1 week ago

I guess it may have something to do with your deployment environment.

zhzhuang-zju commented 6 days ago

I also encountered the same problem. Refer to https://github.com/kubernetes-sigs/controller-runtime/issues/2622#issuecomment-1855819427, it was a breaking change in the release notes of 0.15.0. And we could silence the log.SetLogger(...) was never called; logs will not be displayed error by manually calling function controllerruntime.SetLogger, like

# cmd/webhook/main.go
func main() {
    ctx := controllerruntime.SetupSignalHandler()
    // This is required because controller-runtime expects its consumers to
    // set a logger through log.SetLogger within 30 seconds of the program's
    // initalization. We have our own logger and can configure controller-runtime's
    // logger to do nothing.
    controllerruntime.SetLogger(logr.New(log.NullLogSink{}))
    cmd := app.NewWebhookCommand(ctx)
    code := cli.Run(cmd)
    os.Exit(code)
}
XiShanYongYe-Chang commented 6 days ago

Thanks! @zhzhuang-zju /cc @liangyuanpeng @whitewindmills

zhzhuang-zju commented 6 days ago

/assign

RainbowMango commented 5 days ago

PS: Here is the referencing code of controller-runtime: https://github.com/kubernetes-sigs/controller-runtime/blob/761478ab2aced7167817256539239c626ee8e3ba/pkg/log/log.go#L58.