fix: honor klog -stderrthreshold even when -logtostderr is true#18231
Merged
k8s-ci-robot merged 1 commit intokubernetes:masterfrom Apr 23, 2026
Merged
Conversation
klog v2 defaults -logtostderr to true, which silently ignores -stderrthreshold — all log levels go to stderr unconditionally. This has been an open issue since 2020 (kubernetes/klog#212). klog v2.140.0 introduced a fix behind an opt-in flag (legacy_stderr_threshold_behavior). This commit enables the fix across all klog.InitFlags call sites so that -stderrthreshold is honored, while preserving the current default behavior (stderrthreshold=INFO means all logs still go to stderr unless the user overrides it on the command line). Ref: kubernetes/klog#212 Ref: kubernetes/klog#432 Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Contributor
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hakman The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
klog v2 defaults
-logtostderrtotrue, which silently ignores any-stderrthresholdvalue the user sets — all log levels are sent to stderrunconditionally. This has been a known issue since 2020
(kubernetes/klog#212).
klog v2.140.0 (already the version in kops
go.mod) introduced thelegacy_stderr_threshold_behaviorflag that, when set tofalse, makes-stderrthresholdwork as documented even when-logtostderristrue(kubernetes/klog#432).
This PR opts into the fix across all 9
klog.InitFlagscall sites (onewas already patched in
cmd/kops/root.go; this commit normalizes the commentand adds the same two
Setcalls to the remaining 8 sites):channels/cmd/channels/main.goflag(default)cmd/kops/root.gogoflag(alias forflag)cmd/kops-controller/main.goflag(default)cmd/kube-apiserver-healthcheck/main.goflag(default)cmd/nodeup/main.goflag(default)dns-controller/cmd/dns-controller/main.goflag(default)protokube/cmd/protokube/main.goflag(default)tools/otel/traceserver/main.goflag(default)upup/tools/generators/fitask/main.goflag(default)tests/e2e/kubetest2-kops/deployer/deployer.goklogFlags(custom)The default
stderrthreshold=INFOpreserves current behavior — all logsstill go to stderr by default. The difference is that users can now
meaningfully set
-stderrthreshold=WARNING(or higher) to filter outlower-severity messages.
What changed
After each
klog.InitFlags(...)call, two flag-set operations are added:No dependency changes — kops already uses klog v2.140.0.
References