Skip to content

Commit c187e3a

Browse files
fix: honor klog -stderrthreshold when -logtostderr is enabled
klog v2 defaults -logtostderr to true. When this flag is active, the -stderrthreshold flag is silently ignored — all log messages are unconditionally written to stderr regardless of severity. Bump klog from v2.130.1 to v2.140.0 in both staging modules (cli, code-generator) and opt into the fixed behavior in all 6 binaries (kubectl-kcp, kubectl-ws, kubectl-create-workspace, cluster-client-gen, cluster-informer-gen, cluster-lister-gen). The default stderrthreshold remains INFO so the observable behavior is unchanged. Ref: kubernetes/klog#212, kubernetes/klog#432 Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
1 parent 8482e7e commit c187e3a

10 files changed

Lines changed: 36 additions & 6 deletions

File tree

staging/src/github.com/kcp-dev/cli/cmd/kubectl-create-workspace/cmd/kubectlCreateWorkspace.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ func KubectlCreateWorkspaceCommand() *cobra.Command {
3939
// setup klog
4040
fs := goflags.NewFlagSet("klog", goflags.PanicOnError)
4141
klog.InitFlags(fs)
42+
// Opt into the new klog behavior so that -stderrthreshold is honored even
43+
// when -logtostderr=true (the default).
44+
// Ref: kubernetes/klog#212, kubernetes/klog#432
45+
_ = fs.Set("legacy_stderr_threshold_behavior", "false")
46+
_ = fs.Set("stderrthreshold", "INFO")
4247
createWorkspaceCommand.PersistentFlags().AddGoFlagSet(fs)
4348
return createWorkspaceCommand
4449
}

staging/src/github.com/kcp-dev/cli/cmd/kubectl-kcp/cmd/kubectlKcp.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ func KubectlKcpCommand() *cobra.Command {
5656
// setup klog
5757
fs := goflags.NewFlagSet("klog", goflags.PanicOnError)
5858
klog.InitFlags(fs)
59+
// Opt into the new klog behavior so that -stderrthreshold is honored even
60+
// when -logtostderr=true (the default).
61+
// Ref: kubernetes/klog#212, kubernetes/klog#432
62+
_ = fs.Set("legacy_stderr_threshold_behavior", "false")
63+
_ = fs.Set("stderrthreshold", "INFO")
5964
root.PersistentFlags().AddGoFlagSet(fs)
6065

6166
if v := version.Get().String(); len(v) == 0 {

staging/src/github.com/kcp-dev/cli/cmd/kubectl-ws/cmd/kubectlWs.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ func KubectlWsCommand() *cobra.Command {
3939
// setup klog
4040
fs := goflags.NewFlagSet("klog", goflags.PanicOnError)
4141
klog.InitFlags(fs)
42+
// Opt into the new klog behavior so that -stderrthreshold is honored even
43+
// when -logtostderr=true (the default).
44+
// Ref: kubernetes/klog#212, kubernetes/klog#432
45+
_ = fs.Set("legacy_stderr_threshold_behavior", "false")
46+
_ = fs.Set("stderrthreshold", "INFO")
4247
wsCommand.PersistentFlags().AddGoFlagSet(fs)
4348
return wsCommand
4449
}

staging/src/github.com/kcp-dev/cli/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
k8s.io/cli-runtime v0.33.3
1919
k8s.io/client-go v0.35.1
2020
k8s.io/component-base v0.35.1
21-
k8s.io/klog/v2 v2.130.1
21+
k8s.io/klog/v2 v2.140.0
2222
)
2323

2424
replace (

staging/src/github.com/kcp-dev/cli/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ k8s.io/client-go v0.35.1 h1:+eSfZHwuo/I19PaSxqumjqZ9l5XiTEKbIaJ+j1wLcLM=
226226
k8s.io/client-go v0.35.1/go.mod h1:1p1KxDt3a0ruRfc/pG4qT/3oHmUj1AhSHEcxNSGg+OA=
227227
k8s.io/component-base v0.35.1 h1:XgvpRf4srp037QWfGBLFsYMUQJkE5yMa94UsJU7pmcE=
228228
k8s.io/component-base v0.35.1/go.mod h1:HI/6jXlwkiOL5zL9bqA3en1Ygv60F03oEpnuU1G56Bs=
229-
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
230-
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
229+
k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc=
230+
k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0=
231231
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 h1:Y3gxNAuB0OBLImH611+UDZcmKS3g6CthxToOb37KgwE=
232232
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912/go.mod h1:kdmbQkyfwUagLfXIad1y2TdrjPFWp2Q89B3qkRwf/pQ=
233233
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 h1:SjGebBtkBqHFOli+05xYbK8YF1Dzkbzn+gDM4X9T4Ck=

staging/src/github.com/kcp-dev/code-generator/cmd/cluster-client-gen/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ func main() {
3939

4040
args.AddFlags(pflag.CommandLine, "k8s.io/kubernetes/pkg/apis") // TODO: move this input path out of client-gen
4141
_ = flag.Set("logtostderr", "true")
42+
// Opt into the new klog behavior so that -stderrthreshold is honored even
43+
// when -logtostderr=true (the default).
44+
// Ref: kubernetes/klog#212, kubernetes/klog#432
45+
_ = flag.Set("legacy_stderr_threshold_behavior", "false")
46+
_ = flag.Set("stderrthreshold", "INFO")
4247
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
4348
pflag.Parse()
4449

staging/src/github.com/kcp-dev/code-generator/cmd/cluster-informer-gen/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ func main() {
3737

3838
args.AddFlags(pflag.CommandLine)
3939
_ = flag.Set("logtostderr", "true")
40+
// Opt into the new klog behavior so that -stderrthreshold is honored even
41+
// when -logtostderr=true (the default).
42+
// Ref: kubernetes/klog#212, kubernetes/klog#432
43+
_ = flag.Set("legacy_stderr_threshold_behavior", "false")
44+
_ = flag.Set("stderrthreshold", "INFO")
4045
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
4146
pflag.Parse()
4247

staging/src/github.com/kcp-dev/code-generator/cmd/cluster-lister-gen/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ func main() {
3737

3838
args.AddFlags(pflag.CommandLine)
3939
_ = flag.Set("logtostderr", "true")
40+
// Opt into the new klog behavior so that -stderrthreshold is honored even
41+
// when -logtostderr=true (the default).
42+
// Ref: kubernetes/klog#212, kubernetes/klog#432
43+
_ = flag.Set("legacy_stderr_threshold_behavior", "false")
44+
_ = flag.Set("stderrthreshold", "INFO")
4045
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
4146
pflag.Parse()
4247

staging/src/github.com/kcp-dev/code-generator/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
golang.org/x/text v0.31.0
88
k8s.io/code-generator v0.35.1
99
k8s.io/gengo/v2 v2.0.0-20250922181213-ec3ebc5fd46b
10-
k8s.io/klog/v2 v2.130.1
10+
k8s.io/klog/v2 v2.140.0
1111
)
1212

1313
require (

staging/src/github.com/kcp-dev/code-generator/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ k8s.io/code-generator v0.35.1 h1:yLKR2la7Z9cWT5qmk67ayx8xXLM4RRKQMnC8YPvTWRI=
1616
k8s.io/code-generator v0.35.1/go.mod h1:F2Fhm7aA69tC/VkMXLDokdovltXEF026Tb9yfQXQWKg=
1717
k8s.io/gengo/v2 v2.0.0-20250922181213-ec3ebc5fd46b h1:gMplByicHV/TJBizHd9aVEsTYoJBnnUAT5MHlTkbjhQ=
1818
k8s.io/gengo/v2 v2.0.0-20250922181213-ec3ebc5fd46b/go.mod h1:CgujABENc3KuTrcsdpGmrrASjtQsWCT7R99mEV4U/fM=
19-
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
20-
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
19+
k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc=
20+
k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0=

0 commit comments

Comments
 (0)