Skip to content

Commit b584613

Browse files
pierluigilenocithomasferrandiz
authored andcommitted
fix: honor --stderrthreshold flag when --logtostderr is enabled
When logtostderr is enabled, klog's legacy behavior ignores the stderrthreshold flag. This opts into the fixed behavior introduced in klog v2.130.0 by setting legacy_stderr_threshold_behavior=false. See: kubernetes/klog#432 Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
1 parent eeab1c3 commit b584613

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
k8s.io/api v0.32.10
2727
k8s.io/apimachinery v0.32.10
2828
k8s.io/client-go v0.32.10
29-
k8s.io/klog/v2 v2.130.1
29+
k8s.io/klog/v2 v2.140.0
3030
)
3131

3232
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,8 @@ k8s.io/apimachinery v0.32.10 h1:SAg2kUPLYRcBJQj66oniP1BnXSqw+l1GvJFsJlBmVvQ=
432432
k8s.io/apimachinery v0.32.10/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE=
433433
k8s.io/client-go v0.32.10 h1:MFmIjsKtcnn7mStjrJG1ZW2WzLsKKn6ZtL9hHM/W0xU=
434434
k8s.io/client-go v0.32.10/go.mod h1:qJy/Ws3zSwnu/nD75D+/of1uxbwWHxrYT5P3FuobVLI=
435-
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
436-
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
435+
k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc=
436+
k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0=
437437
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f h1:GA7//TjRY9yWGy1poLzYYJJ4JRdzg3+O6e8I+e+8T5Y=
438438
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f/go.mod h1:R/HEjbvWI0qdfb8viZUeVZm0X6IZnxAydC7YU42CMw4=
439439
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 h1:M3sRQVHv7vB20Xc2ybTt7ODCeFj6JSWYFzOFnYeS6Ro=

main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ func init() {
147147
os.Exit(1)
148148
}
149149

150+
// Opt into the fixed klog behavior so the --stderrthreshold flag is honored
151+
// even when --logtostderr is enabled. See https://github.com/kubernetes/klog/issues/432
152+
if err := flag.Set("legacy_stderr_threshold_behavior", "false"); err != nil {
153+
log.Error("Can't set the legacy_stderr_threshold_behavior flag", err)
154+
os.Exit(1)
155+
}
156+
if err := flag.Set("stderrthreshold", "INFO"); err != nil {
157+
log.Error("Can't set the stderrthreshold flag", err)
158+
os.Exit(1)
159+
}
160+
150161
// Only copy the non file logging options from klog
151162
copyFlag("v")
152163
copyFlag("vmodule")

0 commit comments

Comments
 (0)