fix: honor -stderrthreshold when -logtostderr is true (default)

klog v2 defaults -logtostderr to true, which silently ignores the
-stderrthreshold flag — all log levels are unconditionally sent to
stderr. This makes it impossible for log-aggregation systems to filter
by severity.

Bump klog to v2.140.0 and opt into the fixed behavior by setting
legacy_stderr_threshold_behavior=false and stderrthreshold=INFO (which
preserves current output while letting users override via CLI flags).

Ref: kubernetes/klog#212, kubernetes/klog#432
Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
This commit is contained in:
Pierluigi Lenoci
2026-04-22 09:44:47 +02:00
parent 2d6865d6e5
commit 0fa1910afb
3 changed files with 8 additions and 3 deletions
+5
View File
@@ -132,6 +132,11 @@ operations can also be performed as 'velero backup get' and 'velero schedule cre
// init and add the klog flags
klog.InitFlags(flag.CommandLine)
// Opt into the new klog behavior so that -stderrthreshold is honored even
// when -logtostderr=true (the default).
// Ref: kubernetes/klog#212, kubernetes/klog#432
flag.CommandLine.Set("legacy_stderr_threshold_behavior", "false") //nolint:errcheck
flag.CommandLine.Set("stderrthreshold", "INFO") //nolint:errcheck
c.PersistentFlags().AddGoFlagSet(flag.CommandLine)
return c