Skip to content

Migrate to klog/v2 v2.140.0 and honor stderrthreshold when logtostderr is enabled#3801

Open
pierluigilenoci wants to merge 1 commit intooperator-framework:masterfrom
pierluigilenoci:fix/honor-stderrthreshold
Open

Migrate to klog/v2 v2.140.0 and honor stderrthreshold when logtostderr is enabled#3801
pierluigilenoci wants to merge 1 commit intooperator-framework:masterfrom
pierluigilenoci:fix/honor-stderrthreshold

Conversation

@pierluigilenoci
Copy link

Summary

  • Migrate all direct k8s.io/klog (v1) imports to k8s.io/klog/v2 and bump to v2.140.0 which includes the fix for stderrthreshold not honored when logtostderr is set kubernetes/klog#212.
  • Opt into the new klog behavior by setting -legacy_stderr_threshold_behavior=false so that -stderrthreshold is honored even when -logtostderr=true (the klog default).
  • Set stderrthreshold=INFO to preserve backward-compatible behavior (all logs still appear on stderr by default). Users can now override -stderrthreshold to WARNING or ERROR to reduce stderr noise.
  • Wire klog flags into pflag.CommandLine in cmd/olm/main.go so that klog flags (like -v, -stderrthreshold) are actually accessible from the command line (they were previously registered but never parsed).
  • Fix klog v1→v2 API incompatibility: klog.V() returns Verbose struct in v2 (not bool) — use .Enabled() for conditional checks.

This addresses #2131 where all OLM logs are classified as ERROR by log aggregation systems (DataDog, CloudWatch, GCP Cloud Logging) because everything is unconditionally written to stderr regardless of severity.

Background

When -logtostderr=true (klog's default), the -stderrthreshold flag was completely ignored — all log levels were written to stderr. Log aggregation systems that infer severity from the output stream (stdout=INFO, stderr=ERROR) would misclassify every OLM log message as an error.

klog v2.140.0 (kubernetes/klog#432) introduced a fix behind the -legacy_stderr_threshold_behavior flag. Setting it to false enables proper severity-based filtering on the stderr path.

The stderrthreshold=INFO default preserves existing behavior (all logs on stderr), while giving operators the ability to set -stderrthreshold=WARNING or -stderrthreshold=ERROR to only send higher-severity messages to stderr.

Test plan

  • Existing unit tests pass
  • Deploy with default configuration — all logs appear on stderr (backward compatible)
  • Deploy with -stderrthreshold=WARNING — only WARNING and above appear on stderr

Fixes #2131

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

Migrate all direct klog v1 imports to klog/v2 and bump to v2.140.0
which includes the fix for kubernetes/klog#212.

Opt into the new klog behavior by setting
-legacy_stderr_threshold_behavior=false so that -stderrthreshold is
honored even when -logtostderr=true (the default). Set
stderrthreshold=INFO to preserve backward-compatible behavior while
allowing users to override it to WARNING or ERROR to reduce stderr
noise.

Also wire klog flags into pflag.CommandLine in cmd/olm so that klog
flags (like -v, -stderrthreshold) are actually accessible from the
command line.

Fix klog v1→v2 API incompatibility: klog.V() returns Verbose struct
in v2, not bool — use .Enabled() for conditional checks.

Fixes operator-framework#2131

Ref: kubernetes/klog#212, kubernetes/klog#432
Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
@openshift-ci openshift-ci bot requested a review from camilamacedo86 March 24, 2026 11:55
@openshift-ci
Copy link

openshift-ci bot commented Mar 24, 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 dtfranz 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

@openshift-ci openshift-ci bot requested a review from kevinrizza March 24, 2026 11:55
@openshift-ci
Copy link

openshift-ci bot commented Mar 24, 2026

Hi @pierluigilenoci. Thanks for your PR.

I'm waiting for a operator-framework 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 24, 2026
@pierluigilenoci
Copy link
Author

cc @joelanford @kevinrizza @perdasilva — would you be able to review this when you get a chance? This PR migrates from klog v1 to v2 and opts into the klog fix for kubernetes/klog#212 so that -stderrthreshold is honored even when -logtostderr=true. Related: operator-framework/operator-lifecycle-manager#2131. The PR also needs /ok-to-test from an org member to run CI.

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

Labels

needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OLM seems to be only logging to stderr

1 participant