-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Honor stderrthreshold when logtostderr is enabled #7568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ import ( | |
| clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
| _ "k8s.io/client-go/plugin/pkg/client/auth" | ||
| "k8s.io/client-go/tools/cache" | ||
| "k8s.io/klog/v2" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| ctrlcache "sigs.k8s.io/controller-runtime/pkg/cache" | ||
| "sigs.k8s.io/controller-runtime/pkg/controller" | ||
|
|
@@ -118,6 +119,21 @@ func main() { | |
| pflag.StringVar(&filePathAuthRootPath, "filepath-auth-root-path", "", "Allowed filesystem path for KEDA to read auth from.") | ||
| opts := zap.Options{} | ||
| opts.BindFlags(flag.CommandLine) | ||
|
|
||
| // Register klog flags on flag.CommandLine so they can be set programmatically. | ||
| klog.InitFlags(nil) | ||
|
|
||
| // Opt into the new klog behavior so that -stderrthreshold is honored even | ||
| // when -logtostderr=true (the default). Without this, all log levels are | ||
| // unconditionally sent to stderr and users cannot filter by severity. | ||
| // Requires klog v2.140.0+ (kubernetes/klog#432). | ||
| if err := flag.CommandLine.Set("legacy_stderr_threshold_behavior", "false"); err != nil { | ||
| klog.Fatalf("Failed to set legacy_stderr_threshold_behavior: %v", err) | ||
| } | ||
| if err := flag.CommandLine.Set("stderrthreshold", "INFO"); err != nil { | ||
| klog.Fatalf("Failed to set stderrthreshold: %v", err) | ||
| } | ||
|
Comment on lines
+126
to
+135
|
||
|
|
||
| pflag.CommandLine.AddGoFlagSet(flag.CommandLine) | ||
| pflag.Parse() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ import ( | |
| utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
| clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
| _ "k8s.io/client-go/plugin/pkg/client/auth" | ||
| "k8s.io/klog/v2" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/healthz" | ||
| "sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
|
|
@@ -73,6 +74,21 @@ func main() { | |
|
|
||
| opts := zap.Options{} | ||
| opts.BindFlags(flag.CommandLine) | ||
|
|
||
| // Register klog flags on flag.CommandLine so they can be set programmatically. | ||
| klog.InitFlags(nil) | ||
|
|
||
| // Opt into the new klog behavior so that -stderrthreshold is honored even | ||
| // when -logtostderr=true (the default). Without this, all log levels are | ||
| // unconditionally sent to stderr and users cannot filter by severity. | ||
| // Requires klog v2.140.0+ (kubernetes/klog#432). | ||
| if err := flag.CommandLine.Set("legacy_stderr_threshold_behavior", "false"); err != nil { | ||
| klog.Fatalf("Failed to set legacy_stderr_threshold_behavior: %v", err) | ||
| } | ||
| if err := flag.CommandLine.Set("stderrthreshold", "INFO"); err != nil { | ||
| klog.Fatalf("Failed to set stderrthreshold: %v", err) | ||
| } | ||
|
Comment on lines
+81
to
+90
|
||
|
|
||
| pflag.CommandLine.AddGoFlagSet(flag.CommandLine) | ||
| pflag.Parse() | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These
flag.CommandLine.Set(...)calls will fail unless klog has registered its flags onflag.CommandLine(viaklog.InitFlags(...)). This file currently doesn’t initialize klog flags, so the adapter will exit early with "no such flag". Also note that this command already defines a pflag--stderrthreshold(currently documented as a no-op); even after initializing klog flags, users changing the existing pflag won’t affect klog unless you explicitly propagate the parsedstdErrThresholdvalue into klog (for example, after parsing, callflag.CommandLine.Set("stderrthreshold", stdErrThreshold)when the flag was provided).