Skip to content

fix: honor -stderrthreshold flag in klog v2#3086

Draft
pierluigilenoci wants to merge 2 commits intokubesphere:mainfrom
pierluigilenoci:fix/honor-stderrthreshold
Draft

fix: honor -stderrthreshold flag in klog v2#3086
pierluigilenoci wants to merge 2 commits intokubesphere:mainfrom
pierluigilenoci:fix/honor-stderrthreshold

Conversation

@pierluigilenoci
Copy link
Copy Markdown

What this PR does

klog v2 defaults -logtostderr=true, which silently ignores the
-stderrthreshold flag (kubernetes/klog#212).
Users who set -stderrthreshold expect it to control which severity
level is written to stderr, but the flag has no effect because
-logtostderr takes precedence.

klog v2.140.0 introduced the legacy_stderr_threshold_behavior
flag to restore the intended behaviour
(kubernetes/klog#432).

Changes

  • cmd/kk/app/options/other.go and
    cmd/controller-manager/app/options/common.go: after every
    klog.InitFlags() call, set logtostderr=false and
    legacy_stderr_threshold_behavior=true so that -stderrthreshold
    works as expected.
  • go.mod: bump k8s.io/klog/v2 from v2.130.1 to v2.140.0.

Why

Without this fix, any -stderrthreshold value passed to kk or
controller-manager is silently ignored, making it impossible to
suppress low-severity log output on stderr.

How to test

go build ./cmd/kk/...
go build ./cmd/controller-manager/...

Both binaries compile and the new flag values are set programmatically
(no user-facing CLI change).

klog v2 defaults -logtostderr=true, which silently ignores the
-stderrthreshold flag (kubernetes/klog#212). klog v2.140.0
introduced the legacy_stderr_threshold_behavior flag to fix this
(kubernetes/klog#432).

After every klog.InitFlags() call, set logtostderr=false and
legacy_stderr_threshold_behavior=true so that -stderrthreshold
works as expected.

Bump k8s.io/klog/v2 from v2.130.1 to v2.140.0.

Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
@kubesphere-prow
Copy link
Copy Markdown

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubesphere-prow kubesphere-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed labels Apr 24, 2026
@kubesphere-prow
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pierluigilenoci
Once this PR has been reviewed and has the lgtm label, please assign zuoxuesong-worker for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@kubesphere-prow
Copy link
Copy Markdown

Welcome @pierluigilenoci! It looks like this is your first PR to kubesphere/kubekey 🎉

@kubesphere-prow kubesphere-prow Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 24, 2026
Set legacy_stderr_threshold_behavior=false (not true) to enable the fix,
and set stderrthreshold=INFO (not logtostderr=false) to preserve default
behavior while allowing users to override on the command line.

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
@kubesphere-prow
Copy link
Copy Markdown

This PR has multiple commits, and the default merge method is: squash.
You can request commits to be merged using the label: tide/merge-method-merge

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the k8s.io/klog/v2 dependency to version 2.140.0 and configures the logtostderr and legacy_stderr_threshold_behavior flags in cmd/controller-manager/app/options/common.go and cmd/kk/app/options/other.go to resolve an issue where -stderrthreshold was ignored. The review feedback recommends adding error handling for the local.Set calls to prevent silent configuration failures during application startup.

Comment on lines +164 to +165
_ = local.Set("legacy_stderr_threshold_behavior", "false")
_ = local.Set("stderrthreshold", "INFO")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The errors returned by local.Set are being ignored. While it's unlikely to fail in this case, it's a good practice to handle errors during application initialization. A failure to set these flags would lead to incorrect logging behavior that could be difficult to debug. Consider checking the error and logging a fatal error if setting the flag fails, to ensure the application exits if it cannot be configured correctly.

	if err := local.Set("logtostderr", "false"); err != nil {
		klog.Fatalf("failed to set klog logtostderr flag: %v", err)
	}
	if err := local.Set("legacy_stderr_threshold_behavior", "true"); err != nil {
		klog.Fatalf("failed to set klog legacy_stderr_threshold_behavior flag: %v", err)
	}

Comment on lines +165 to +166
_ = local.Set("legacy_stderr_threshold_behavior", "false")
_ = local.Set("stderrthreshold", "INFO")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The errors returned by local.Set are being ignored. While it's unlikely to fail in this case, it's a good practice to handle errors during application initialization. A failure to set these flags would lead to incorrect logging behavior that could be difficult to debug. Consider checking the error and logging a fatal error if setting the flag fails, to ensure the application exits if it cannot be configured correctly.

	if err := local.Set("logtostderr", "false"); err != nil {
		klog.Fatalf("failed to set klog logtostderr flag: %v", err)
	}
	if err := local.Set("legacy_stderr_threshold_behavior", "true"); err != nil {
		klog.Fatalf("failed to set klog legacy_stderr_threshold_behavior flag: %v", err)
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/release-note-label-needed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant