From 4492a1a0d4d88625c7a722a30e62122be0ef83cd Mon Sep 17 00:00:00 2001 From: Pierluigi Lenoci Date: Wed, 22 Apr 2026 19:41:56 +0200 Subject: [PATCH] fix: honor klog -stderrthreshold even when -logtostderr is true klog v2 defaults -logtostderr to true, which silently causes -stderrthreshold to be ignored. klog v2.140.0 introduced the legacy_stderr_threshold_behavior flag (kubernetes/klog#432) to decouple the two settings. Set legacy_stderr_threshold_behavior=false so that users can control log verbosity on stderr via -stderrthreshold as expected. Bump k8s.io/klog/v2 from v2.130.1 to v2.140.0 to pick up the fix. Ref: kubernetes/klog#212, kubernetes/klog#432 Signed-off-by: Pierluigi Lenoci --- go.mod | 2 +- go.sum | 4 ++-- main.go | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3afa56c..d63facb 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21.0 require ( github.com/russross/blackfriday/v2 v2.1.0 k8s.io/gengo/v2 v2.0.0-20250106234829-0359904fc2a6 - k8s.io/klog/v2 v2.130.1 + k8s.io/klog/v2 v2.140.0 ) require ( diff --git a/go.sum b/go.sum index 942f510..b07d3db 100644 --- a/go.sum +++ b/go.sum @@ -12,5 +12,5 @@ golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA= golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= k8s.io/gengo/v2 v2.0.0-20250106234829-0359904fc2a6 h1:SdzkGIk4b5LFkVO36PuO0Bx4tpBDJDpNN0F1/v8JM5c= k8s.io/gengo/v2 v2.0.0-20250106234829-0359904fc2a6/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU= -k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= -k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= +k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc= +k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0= diff --git a/main.go b/main.go index 0eaba72..2d65fad 100644 --- a/main.go +++ b/main.go @@ -87,6 +87,10 @@ func (v *apiPackage) identifier() string { return fmt.Sprintf("%s/%s", v.apiGrou func init() { klog.InitFlags(nil) flag.Set("alsologtostderr", "true") // for klog + // 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.Set("legacy_stderr_threshold_behavior", "false") flag.Parse() commitHash, commitTime, dirtyBuild := getBuildInfo()