Skip to content

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

Draft
pierluigilenoci wants to merge 1 commit intoGoogleCloudPlatform:masterfrom
pierluigilenoci:fix/honor-stderrthreshold
Draft

fix: honor klog -stderrthreshold even when -logtostderr is true#7662
pierluigilenoci wants to merge 1 commit intoGoogleCloudPlatform:masterfrom
pierluigilenoci:fix/honor-stderrthreshold

Conversation

@pierluigilenoci
Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it:

klog v2 defaults -logtostderr to true, which silently causes
-stderrthreshold to be ignored. This means operators cannot tune the
severity threshold for stderr output — every log line is already sent to
stderr regardless.

klog v2.140.0 introduced the legacy_stderr_threshold_behavior flag
(kubernetes/klog#432) to fix this. Setting it to false immediately
after klog.InitFlags restores proper -stderrthreshold semantics.

This PR:

  1. Bumps k8s.io/klog/v2 from v2.130.1 → v2.140.0 in every
    go.mod (root, dev/tools/controllerbuilder, experiments/composite,
    experiments/tools/licensescan, mockgcp) and the root replace
    directive.
  2. Patches every klog.InitFlags call site (10 files) to opt into
    the new behavior:
    • flag.Set("legacy_stderr_threshold_behavior", "false") /
      flag.Set("stderrthreshold", "INFO") for sites using the default
      flag.CommandLine
    • fs.Set(...) for sites using a custom flag.FlagSet
  3. Leaves dev/tools/controllerbuilder/cmd/resourcerunner/main.go
    untouched — it imports klog v1, which doesn't have this flag.

Which issue(s) this PR fixes:

Ref: kubernetes/klog#212, kubernetes/klog#432

Does this PR introduce a user-facing change?

NONE

@google-oss-prow
Copy link
Copy Markdown
Contributor

@pierluigilenoci: The label(s) kind/bug cannot be applied, because the repository doesn't have them.

Details

In response to this:

What type of PR is this?

/kind bug

What this PR does / why we need it:

klog v2 defaults -logtostderr to true, which silently causes
-stderrthreshold to be ignored. This means operators cannot tune the
severity threshold for stderr output — every log line is already sent to
stderr regardless.

klog v2.140.0 introduced the legacy_stderr_threshold_behavior flag
(kubernetes/klog#432) to fix this. Setting it to false immediately
after klog.InitFlags restores proper -stderrthreshold semantics.

This PR:

  1. Bumps k8s.io/klog/v2 from v2.130.1 → v2.140.0 in every
    go.mod (root, dev/tools/controllerbuilder, experiments/composite,
    experiments/tools/licensescan, mockgcp) and the root replace
    directive.
  2. Patches every klog.InitFlags call site (10 files) to opt into
    the new behavior:
  • flag.Set("legacy_stderr_threshold_behavior", "false") /
    flag.Set("stderrthreshold", "INFO") for sites using the default
    flag.CommandLine
  • fs.Set(...) for sites using a custom flag.FlagSet
  1. Leaves dev/tools/controllerbuilder/cmd/resourcerunner/main.go
    untouched — it imports klog v1, which doesn't have this flag.

Which issue(s) this PR fixes:

Ref: kubernetes/klog#212, kubernetes/klog#432

Does this PR introduce a user-facing change?

NONE

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/test-infra repository.

@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

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.

Note: dev/tools/controllerbuilder/cmd/resourcerunner/main.go is left
untouched because it imports klog v1, which does not have this flag.

Ref: kubernetes/klog#212, kubernetes/klog#432
Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
@pierluigilenoci pierluigilenoci force-pushed the fix/honor-stderrthreshold branch from 1dac2ba to ac07fb3 Compare April 24, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant