Skip to content

klog --stderrthreshold flag silently ignored when --logtostderr is enabled #9658

@pierluigilenoci

Description

@pierluigilenoci

Bug Description

When --logtostderr is enabled (Velero's default), the --stderrthreshold flag is silently ignored due to a legacy behavior in klog. This means all log levels (INFO, WARNING, ERROR) are always written to stderr regardless of the --stderrthreshold setting.

This was identified as a bug in kubernetes/klog#432 and fixed in klog v2.140.0 by introducing a new behavior mode that must be explicitly opted into.

Steps to Reproduce

  1. Start Velero server with --stderrthreshold=WARNING (attempting to only see warnings and errors on stderr)
  2. Observe that INFO messages still appear on stderr
  3. The flag has no effect because --logtostderr=true (the default) bypasses the threshold check

Expected Behavior

When --stderrthreshold=WARNING is set, only WARNING and ERROR level messages should appear on stderr. INFO messages should be suppressed from stderr output.

Actual Behavior

All log levels (INFO, WARNING, ERROR) appear on stderr regardless of the --stderrthreshold setting, because the legacy klog behavior ignores the threshold when logtostderr is true.

Fix

  • Bump k8s.io/klog/v2 to v2.140.0
  • Set legacy_stderr_threshold_behavior=false after klog.InitFlags() to opt into the fixed behavior
  • Set stderrthreshold=INFO to maintain current behavior (all logs to stderr) while making the flag actually functional for users who want to customize it

References

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions