karmada-io / karmada

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

silence the 'log.SetLogger(...) was never called; logs will not be displayed' error #4885

Closed zhzhuang-zju closed 2 weeks ago

zhzhuang-zju commented 2 weeks ago

What type of PR is this? /kind cleanup

What this PR does / why we need it: Refer to #4868, when karmada-webhook is started, the error log.SetLogger(...) was never called; logs will not be displayed will be displayed, which is very confusing. Here's the answer to why this log appears and how to fix it. Viewing the function call chain, refer to: https://github.com/karmada-io/karmada/blob/95bf37f4d4b82cd9ab68e5879020c070acec1ce0/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/admission/webhook.go#L178-L184 If the log of webhook is nil, it will end up calling https://github.com/karmada-io/karmada/blob/95bf37f4d4b82cd9ab68e5879020c070acec1ce0/vendor/sigs.k8s.io/controller-runtime/pkg/log/log.go#L54-L72 And the SetLogger is not called within the first 30 seconds of a binaries lifetime, finally printed out log.SetLogger(...) was never called; logs will not be displayed error. Through the above analysis, there are two ways to solve this problem:

BTW, it was a breaking change in the release notes 0.15.0 of controller-runtime. Previously, when the pkg/log package was imported, there was an init function that spawned a goroutine, which set a null logger after 30 seconds. Therefore, versions prior to 0.15.0 will not have this problem.

Which issue(s) this PR fixes: Fixes #4868

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

codecov-commenter commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 53.06%. Comparing base (95bf37f) to head (f5de886).

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #4885 +/- ## ========================================== - Coverage 53.07% 53.06% -0.01% ========================================== Files 251 251 Lines 20389 20389 ========================================== - Hits 10821 10820 -1 Misses 8855 8855 - Partials 713 714 +1 ``` | [Flag](https://app.codecov.io/gh/karmada-io/karmada/pull/4885/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=karmada-io) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/karmada-io/karmada/pull/4885/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=karmada-io) | `53.06% <ø> (-0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=karmada-io#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

zhzhuang-zju commented 2 weeks ago

cc @XiShanYongYe-Chang @whitewindmills @liangyuanpeng

zhzhuang-zju commented 2 weeks ago

Does this problem exist other components?

Good advice. I'm lining it up.

zhzhuang-zju commented 2 weeks ago

Does this problem exist other components?

After troubleshooting, components karmada-controller-manager and karmada-metrics-adapter also have this problem. They both call the method https://github.com/karmada-io/karmada/blob/0e3c382bd05d89b7cb44196df7c8bd7f8e104fc0/pkg/util/gclient/gclient.go#L64-L69, which will eventually print log.SetLogger(...) was never called; logs will not be displayed error. Component karmada-controller-manager only calls the above function if len(opts.ClusterAPIKubeconfig) !=0 , and that's why we don't usually find this error in component karmada-controller-manager !

karmada-bot commented 2 weeks ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/karmada-io/karmada/blob/master/OWNERS)~~ [RainbowMango] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
whitewindmills commented 2 weeks ago

/lgtm