Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/controller-manager/app/options/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ func InitGOPS() error {
func AddKlogFlags(fs *pflag.FlagSet) {
local := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(local)

// Opt into the new klog behavior so that -stderrthreshold is honored even
// when -logtostderr=true (the default).
// Ref: kubernetes/klog#212, kubernetes/klog#432
_ = local.Set("legacy_stderr_threshold_behavior", "false")
_ = local.Set("stderrthreshold", "INFO")
Comment on lines +164 to +165
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The errors returned by local.Set are being ignored. While it's unlikely to fail in this case, it's a good practice to handle errors during application initialization. A failure to set these flags would lead to incorrect logging behavior that could be difficult to debug. Consider checking the error and logging a fatal error if setting the flag fails, to ensure the application exits if it cannot be configured correctly.

	if err := local.Set("logtostderr", "false"); err != nil {
		klog.Fatalf("failed to set klog logtostderr flag: %v", err)
	}
	if err := local.Set("legacy_stderr_threshold_behavior", "true"); err != nil {
		klog.Fatalf("failed to set klog legacy_stderr_threshold_behavior flag: %v", err)
	}


local.VisitAll(func(fl *flag.Flag) {
fl.Name = strings.ReplaceAll(fl.Name, "_", "-")
fs.AddGoFlag(fl)
Expand Down
7 changes: 7 additions & 0 deletions cmd/kk/app/options/other.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ func InitGOPS() error {
func AddKlogFlags(fs *pflag.FlagSet) {
local := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(local)

// Opt into the new klog behavior so that -stderrthreshold is honored even
// when -logtostderr=true (the default).
// Ref: kubernetes/klog#212, kubernetes/klog#432
_ = local.Set("legacy_stderr_threshold_behavior", "false")
_ = local.Set("stderrthreshold", "INFO")
Comment on lines +165 to +166
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The errors returned by local.Set are being ignored. While it's unlikely to fail in this case, it's a good practice to handle errors during application initialization. A failure to set these flags would lead to incorrect logging behavior that could be difficult to debug. Consider checking the error and logging a fatal error if setting the flag fails, to ensure the application exits if it cannot be configured correctly.

	if err := local.Set("logtostderr", "false"); err != nil {
		klog.Fatalf("failed to set klog logtostderr flag: %v", err)
	}
	if err := local.Set("legacy_stderr_threshold_behavior", "true"); err != nil {
		klog.Fatalf("failed to set klog legacy_stderr_threshold_behavior flag: %v", err)
	}


local.VisitAll(func(fl *flag.Flag) {
fl.Name = strings.ReplaceAll(fl.Name, "_", "-")
fs.AddGoFlag(fl)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
k8s.io/apiserver v0.35.0
k8s.io/client-go v0.35.0
k8s.io/component-base v0.35.0
k8s.io/klog/v2 v2.130.1
k8s.io/klog/v2 v2.140.0
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4
oras.land/oras-go/v2 v2.6.0
sigs.k8s.io/cluster-api v1.9.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ k8s.io/cluster-bootstrap v0.31.3 h1:O1Yxk1bLaxZvmQCXLaJjj5iJD+lVMfJdRUuKgbUHPlA=
k8s.io/cluster-bootstrap v0.31.3/go.mod h1:TI6TCsQQB4FfcryWgNO3SLXSKWBqHjx4DfyqSFwixj8=
k8s.io/component-base v0.35.0 h1:+yBrOhzri2S1BVqyVSvcM3PtPyx5GUxCK2tinZz1G94=
k8s.io/component-base v0.35.0/go.mod h1:85SCX4UCa6SCFt6p3IKAPej7jSnF3L8EbfSyMZayJR0=
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=
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 h1:Y3gxNAuB0OBLImH611+UDZcmKS3g6CthxToOb37KgwE=
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912/go.mod h1:kdmbQkyfwUagLfXIad1y2TdrjPFWp2Q89B3qkRwf/pQ=
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 h1:SjGebBtkBqHFOli+05xYbK8YF1Dzkbzn+gDM4X9T4Ck=
Expand Down