fix: honor klog -stderrthreshold even when -logtostderr is true#8430
fix: honor klog -stderrthreshold even when -logtostderr is true#8430pierluigilenoci wants to merge 1 commit into
Conversation
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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/cc @cheftako @justinsb @xiaoweim Hi — CI is green and the PR is ready for review. This bumps @cheftako — you reviewed the last two |
BRIEF Change description
Honor
-stderrthresholdeven 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
-logtostderrtotrue, which silently causes-stderrthresholdto 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:
kubernetes/klog#432 (released in klog v2.140.0) introduces a
legacy_stderr_threshold_behaviorflag (defaults totruefor backward compatibility). Setting it tofalsemakes-stderrthresholdwork as users expect.This PR:
k8s.io/klog/v2fromv2.130.1tov2.140.0across all four go modules (go.mod,mockgcp/go.mod,dev/tools/controllerbuilder/go.mod,experiments/tools/licensescan/go.mod);klog.InitFlags(...)call, setslegacy_stderr_threshold_behavior=falseandstderrthreshold=INFO;INFOdefault preserves the current observable behavior — operators who don't pass any flag see no change. Operators who pass-stderrthreshold=WARNING(orERROR) on the command line will now have it actually take effect.Files touched:
cmd/recorder/main.godev/tasks/main.godev/tools/controllerbuilder/cmd/benchmark/type/main.goexperiments/tools/licensescan/main.gomockgcp/tools/gapic/main.gopkg/cli/cmd/preview/execute.gopkg/test/main/testmain.goThe 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
masterand accumulated conflicts aftercontrollerbuilderwas refactored. The new PR is rebased on currentmasterand 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'?