Closed zhzhuang-zju closed 2 weeks ago
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.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
cc @XiShanYongYe-Chang @whitewindmills @liangyuanpeng
Does this problem exist other components?
Good advice. I'm lining it up.
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
!
[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
/lgtm
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 errorlog.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 theSetLogger
is not called within the first 30 seconds of a binaries lifetime, finally printed outlog.SetLogger(...) was never called; logs will not be displayed
error. Through the above analysis, there are two ways to solve this problem:Initializing the webhook's log Looking at the source code, there are two ways to initialize, in addition to the one above, there is one as follows: https://github.com/karmada-io/karmada/blob/95bf37f4d4b82cd9ab68e5879020c070acec1ce0/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/admission/webhook.go#L216-L233 Since this initialization method does not apply to
webhook.Server
, this method does not workcall
SetLogger
to get any actual logging. That's what I ended up using, by callingSetLogger
first to silence the 'log.SetLogger(...) was never called; logs will not be displayed' error.BTW, it was a breaking change in the release notes
0.15.0
ofcontroller-runtime
. Previously, when thepkg/log
package was imported, there was aninit
function that spawned a goroutine, which set a null logger after 30 seconds. Therefore, versions prior to0.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?: