Skip to content

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

Open
pierluigilenoci wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
pierluigilenoci:fix/honor-stderrthreshold-v2
Open

fix: honor klog -stderrthreshold even when -logtostderr is true#8430
pierluigilenoci wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
pierluigilenoci:fix/honor-stderrthreshold-v2

Conversation

@pierluigilenoci
Copy link
Copy Markdown

BRIEF Change description

Honor -stderrthreshold even when -logtostderr=true (the default), by opting into the new klog v2.140.0 behavior introduced in kubernetes/klog#432.

WHY do we need this change?

klog v2 defaults -logtostderr to true, which silently causes -stderrthreshold to be ignored — every log severity (INFO, WARNING, ERROR, FATAL) is unconditionally written to stderr with no way to filter. This has been an open issue since 2020: kubernetes/klog#212.

In production Kubernetes clusters running Config Connector, log-aggregation systems (Fluent Bit, Loki, Datadog, etc.) typically ingest container stderr. Without working severity filtering:

  • log storage costs increase (INFO noise alongside real errors);
  • alerts on stderr output become unreliable (everything goes there);
  • debugging signal gets lost in INFO chatter.

kubernetes/klog#432 (released in klog v2.140.0) introduces a legacy_stderr_threshold_behavior flag (defaults to true for backward compatibility). Setting it to false makes -stderrthreshold work as users expect.

This PR:

  • bumps k8s.io/klog/v2 from v2.130.1 to v2.140.0 across all four go modules (go.mod, mockgcp/go.mod, dev/tools/controllerbuilder/go.mod, experiments/tools/licensescan/go.mod);
  • after every klog.InitFlags(...) call, sets legacy_stderr_threshold_behavior=false and stderrthreshold=INFO;
  • the INFO default preserves the current observable behavior — operators who don't pass any flag see no change. Operators who pass -stderrthreshold=WARNING (or ERROR) on the command line will now have it actually take effect.

Files touched:

  • cmd/recorder/main.go
  • dev/tasks/main.go
  • dev/tools/controllerbuilder/cmd/benchmark/type/main.go
  • experiments/tools/licensescan/main.go
  • mockgcp/tools/gapic/main.go
  • pkg/cli/cmd/preview/execute.go
  • pkg/test/main/testmain.go

The fix is opt-in at the klog level (the new flag defaults to true/legacy), and the default we set here (stderrthreshold=INFO) matches the previous effective behavior, so this change is fully backward compatible.

This replaces #7662, which was opened against an older revision of master and accumulated conflicts after controllerbuilder was refactored. The new PR is rebased on current master and only touches files that still exist.

Special notes for your reviewer:

Identical patches have already been merged into many klog-using projects following the same pattern (e.g. kube-state-metrics, OLM, several CSI drivers, node-problem-detector, nack).

Disclosure: I am the author of kubernetes/klog#432, and I generated and reviewed parts of this patch with AI assistance. Human-reviewed before submission.

Does this PR add something which needs to be 'release noted'?

NONE
  • Reviewer reviewed release note.

klog v2 defaults -logtostderr to true, which silently causes
-stderrthreshold to be ignored. klog v2.140.0 introduced the
legacy_stderr_threshold_behavior flag that restores proper
stderrthreshold semantics.

Bump k8s.io/klog/v2 from v2.130.1 to v2.140.0 across all modules and
set legacy_stderr_threshold_behavior=false + stderrthreshold=INFO
immediately after every klog.InitFlags call.

Ref: kubernetes/klog#212, kubernetes/klog#432
Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
@google-oss-prow
Copy link
Copy Markdown
Contributor

[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 xiaoweim 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

@pierluigilenoci pierluigilenoci marked this pull request as ready for review May 19, 2026 13:32
@pierluigilenoci
Copy link
Copy Markdown
Author

/cc @cheftako @justinsb @xiaoweim

Hi — CI is green and the PR is ready for review. This bumps k8s.io/klog/v2 to v2.140.0 (which is the version that introduces the legacy_stderr_threshold_behavior flag) and opts into the fixed -stderrthreshold semantics across the seven klog.InitFlags call sites that still exist on master.

@cheftako — you reviewed the last two k8s.io/klog/v2 bumps (#7185, #7067), so I'm hoping you might be willing to take a look at this one too. No urgency, whenever convenient. Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant