Skip to content

fix: honor --stderrthreshold flag when --logtostderr is enabled#1485

Open
pierluigilenoci wants to merge 2 commits intoopenshift:mainfrom
pierluigilenoci:fix/honor-stderrthreshold
Open

fix: honor --stderrthreshold flag when --logtostderr is enabled#1485
pierluigilenoci wants to merge 2 commits intoopenshift:mainfrom
pierluigilenoci:fix/honor-stderrthreshold

Conversation

@pierluigilenoci
Copy link
Copy Markdown

What this PR does

When --logtostderr is enabled (which is the default in klog and explicitly set in all entry points), klog's legacy behavior silently ignores the --stderrthreshold flag. This means users cannot filter log output by severity level, even though the flag appears to be available.

This PR opts into the fixed behavior introduced in klog v2.140.0 by setting:

  • legacy_stderr_threshold_behavior=false — disables the legacy override
  • stderrthreshold=INFO — preserves the current default behavior

After this change, users can set --stderrthreshold=WARNING (or any level) and it will work as expected.

All entry points in cmd/ are updated:

  • cmd/machineset
  • cmd/nodelink-controller
  • cmd/vsphere
  • cmd/machine-api-operator (start + version subcommands)
  • cmd/machine-healthcheck

klog dependency updated from v2.130.1 to v2.140.0 (which introduces the legacy_stderr_threshold_behavior flag).

Why

See upstream fix: kubernetes/klog#432

Testing

  • Verified machine-api-operator builds successfully with updated dependency
  • Verified --stderrthreshold=WARNING now correctly filters output when --logtostderr is enabled

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7ee90481-1c9e-48ca-89f1-e4cb11d93c66

📥 Commits

Reviewing files that changed from the base of the PR and between 994d225 and b66c2e6.

📒 Files selected for processing (1)
  • cmd/machine-healthcheck/main.go

Walkthrough

Added programmatic klog flag settings across multiple command entrypoints and bumped klog to v2.140.0: each entrypoint now sets logtostderr=true, disables legacy_stderr_threshold_behavior, and sets stderrthreshold=INFO (with failure handling).

Changes

Cohort / File(s) Summary
klog Dependency Update
go.mod
Bumped k8s.io/klog/v2 from v2.130.1 to v2.140.0.
Stderr threshold & klog flag config
cmd/machine-api-operator/start.go, cmd/machine-api-operator/version.go, cmd/machineset/main.go, cmd/nodelink-controller/main.go, cmd/vsphere/main.go, cmd/machine-healthcheck/main.go
After enabling logtostderr=true, added flag.Set calls to set legacy_stderr_threshold_behavior=false and stderrthreshold=INFO; each call is checked and failure triggers klog.Fatalf.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix stderrthreshold being ignored when logtostderr=true [#432]
Enable opt-in severity filtering via legacy_stderr_threshold_behavior flag [#432] Code force-sets legacy_stderr_threshold_behavior=false programmatically, which opts into the new behavior by default instead of leaving legacy behavior as the default opt-in state.
Set stderrthreshold to a specific level for filtering [#432]
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.11.4)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Mar 28, 2026

Hi @pierluigilenoci. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@openshift-ci openshift-ci bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 28, 2026
@pierluigilenoci
Copy link
Copy Markdown
Author

cc @JoelSpeed @damdo — This is a straightforward klog fix to honor the `--stderrthreshold` flag when `--logtostderr` is enabled. Part of a broader campaign to fix this across the Kubernetes ecosystem (see kubernetes/klog#432). Would appreciate a review when you get a chance!

@openshift-ci openshift-ci bot requested review from damdo and nrb March 28, 2026 21:47
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Mar 28, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign racheljpg for approval. For more information see the 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

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/machine-healthcheck/main.go`:
- Around line 81-89: After calling klog.InitFlags(nil) in main (klog.InitFlags),
set the logtostderr flag to "true" like the other entry points do so the stderr
threshold behavior is applied consistently; add a flag.Set("logtostderr",
"true") immediately after klog.InitFlags(nil) alongside the existing flag.Set
calls for "legacy_stderr_threshold_behavior" and "stderrthreshold" to ensure
klog writes logs to stderr as expected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7a5fba2b-55e2-4542-9ca5-20c81ca353ad

📥 Commits

Reviewing files that changed from the base of the PR and between b8fd345 and e6831c9.

⛔ Files ignored due to path filters (11)
  • go.sum is excluded by !**/*.sum
  • vendor/k8s.io/klog/v2/README.md is excluded by !vendor/**, !**/vendor/**
  • vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go is excluded by !vendor/**, !**/vendor/**
  • vendor/k8s.io/klog/v2/internal/serialize/keyvalues_no_slog.go is excluded by !vendor/**, !**/vendor/**
  • vendor/k8s.io/klog/v2/internal/serialize/keyvalues_slog.go is excluded by !vendor/**, !**/vendor/**
  • vendor/k8s.io/klog/v2/klog.go is excluded by !vendor/**, !**/vendor/**
  • vendor/k8s.io/klog/v2/klogr.go is excluded by !vendor/**, !**/vendor/**
  • vendor/k8s.io/klog/v2/klogr_slog.go is excluded by !vendor/**, !**/vendor/**
  • vendor/k8s.io/klog/v2/textlogger/options.go is excluded by !vendor/**, !**/vendor/**
  • vendor/k8s.io/klog/v2/textlogger/textlogger.go is excluded by !vendor/**, !**/vendor/**
  • vendor/modules.txt is excluded by !vendor/**, !**/vendor/**
📒 Files selected for processing (7)
  • cmd/machine-api-operator/start.go
  • cmd/machine-api-operator/version.go
  • cmd/machine-healthcheck/main.go
  • cmd/machineset/main.go
  • cmd/nodelink-controller/main.go
  • cmd/vsphere/main.go
  • go.mod

All five entry points (vsphere, machineset, machine-api-operator start/version,
nodelink-controller) set logtostderr=true, which causes klog's legacy behavior
to silently ignore the stderrthreshold flag.

This opts into the fixed behavior introduced in klog v2.130.0 by setting
legacy_stderr_threshold_behavior=false in all entry points.

See: kubernetes/klog#432
Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
@pierluigilenoci pierluigilenoci force-pushed the fix/honor-stderrthreshold branch from e6831c9 to 994d225 Compare March 28, 2026 22:19
The machine-healthcheck binary was missing the logtostderr and
stderrthreshold flag.Set calls that were added to all other binaries.

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
@JoelSpeed
Copy link
Copy Markdown
Contributor

/ok-to-test

@openshift-ci openshift-ci bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Indicates a non-member PR verified by an org member that is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants