Skip to content

fix: honor klog -stderrthreshold even when -logtostderr is true#18231

Merged
k8s-ci-robot merged 1 commit intokubernetes:masterfrom
pierluigilenoci:fix/honor-stderrthreshold
Apr 23, 2026
Merged

fix: honor klog -stderrthreshold even when -logtostderr is true#18231
k8s-ci-robot merged 1 commit intokubernetes:masterfrom
pierluigilenoci:fix/honor-stderrthreshold

Conversation

@pierluigilenoci
Copy link
Copy Markdown
Member

Summary

klog v2 defaults -logtostderr to true, which silently ignores any
-stderrthreshold value the user sets — all log levels are sent to stderr
unconditionally. This has been a known issue since 2020
(kubernetes/klog#212).

klog v2.140.0 (already the version in kops go.mod) introduced the
legacy_stderr_threshold_behavior flag that, when set to false, makes
-stderrthreshold work as documented even when -logtostderr is true
(kubernetes/klog#432).

This PR opts into the fix across all 9 klog.InitFlags call sites (one
was already patched in cmd/kops/root.go; this commit normalizes the comment
and adds the same two Set calls to the remaining 8 sites):

File FlagSet
channels/cmd/channels/main.go flag (default)
cmd/kops/root.go goflag (alias for flag)
cmd/kops-controller/main.go flag (default)
cmd/kube-apiserver-healthcheck/main.go flag (default)
cmd/nodeup/main.go flag (default)
dns-controller/cmd/dns-controller/main.go flag (default)
protokube/cmd/protokube/main.go flag (default)
tools/otel/traceserver/main.go flag (default)
upup/tools/generators/fitask/main.go flag (default)
tests/e2e/kubetest2-kops/deployer/deployer.go klogFlags (custom)

The default stderrthreshold=INFO preserves current behavior — all logs
still go to stderr by default. The difference is that users can now
meaningfully set -stderrthreshold=WARNING (or higher) to filter out
lower-severity messages.

What changed

After each klog.InitFlags(...) call, two flag-set operations are added:

// Opt into the new klog behavior so that -stderrthreshold is honored even
// when -logtostderr=true (the default).
// Ref: kubernetes/klog#212, kubernetes/klog#432
flag.Set("legacy_stderr_threshold_behavior", "false")
flag.Set("stderrthreshold", "INFO")

No dependency changes — kops already uses klog v2.140.0.

References

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>
@k8s-ci-robot k8s-ci-robot added area/channels cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/kops-controller size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 23, 2026
Copy link
Copy Markdown
Member

@hakman hakman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 23, 2026
@k8s-ci-robot
Copy link
Copy Markdown
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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 23, 2026
@k8s-ci-robot k8s-ci-robot merged commit 023db17 into kubernetes:master Apr 23, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/channels area/kops-controller cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants