fix: honor -stderrthreshold flag with klog v2 default -logtostderr=true#1677
fix: honor -stderrthreshold flag with klog v2 default -logtostderr=true#1677pierluigilenoci wants to merge 1 commit intokubernetes-sigs:masterfrom
Conversation
klog v2 defaults to -logtostderr=true, which silently causes -stderrthreshold to be ignored. This is a long-standing issue (kubernetes/klog#212) fixed in klog v2.140.0 via the new legacy_stderr_threshold_behavior flag (kubernetes/klog#432). Bump k8s.io/klog/v2 from v2.130.1 to v2.140.0 and set legacy_stderr_threshold_behavior=false in AddKlogFlags so that -stderrthreshold works as expected. Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pierluigilenoci The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
How is this related to -v flag? |
|
Good question! The
They are related because both are part of the same klog flag set initialized in The bug (kubernetes/klog#212) is that |
|
Good question @huww98. They're orthogonal:
The bug this PR fixes: klog v2 defaults to See kubernetes/klog#432 for the upstream context. |
|
OK. But I think we don't care this much. WARNING severity level even not exist in the new structured logging API. We now only have ERROR and INFO severity level, making |
|
@huww98 You're right — with KEP-2845 deprecating klog-specific flags and the move to structured logging, the Closing this PR. |
What this PR does
klog v2 defaults to
-logtostderr=true, which silently causes the-stderrthresholdflag to be ignored. This is a long-standing issue tracked in kubernetes/klog#212.klog v2.140.0 introduced the
legacy_stderr_threshold_behaviorflag to fix this behavior (kubernetes/klog#432).Changes
k8s.io/klog/v2from v2.130.1 to v2.140.0legacy_stderr_threshold_behavior=falseinAddKlogFlags()(pkg/utils/global.go) so that-stderrthresholdis honored even when-logtostderr=true(the default)stderrthreshold=INFOas the default threshold, matching the expected behaviorWhy
Without this fix, operators cannot use
-stderrthresholdto filter log output by severity because klog's legacy behavior unconditionally copies everything to stderr when-logtostderris true (which it is by default).How to test
The only
klog.InitFlagscall in non-vendor, non-test code is inpkg/utils/global.go, which is where the fix is applied.Note
This PR was created with the assistance of AI tooling (Claude Code).