diff --git a/cmd/addon-manager/main.go b/cmd/addon-manager/main.go index 2227acbc..c52aef99 100644 --- a/cmd/addon-manager/main.go +++ b/cmd/addon-manager/main.go @@ -47,6 +47,11 @@ func main() { logger := klogr.New() klog.SetOutput(os.Stdout) klog.InitFlags(flag.CommandLine) + // 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.CommandLine.Set("legacy_stderr_threshold_behavior", "false") //nolint:errcheck + flag.CommandLine.Set("stderrthreshold", "INFO") //nolint:errcheck flag.StringVar(&metricsAddr, "metrics-bind-address", ":48080", "The address the metric endpoint binds to.") flag.StringVar(&probeAddr, "health-probe-bind-address", ":48081", "The address the probe endpoint binds to.") flag.BoolVar(&enableLeaderElection, "leader-elect", false, diff --git a/go.mod b/go.mod index cda5acf3..4250af2e 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( k8s.io/client-go v0.31.10 k8s.io/component-base v0.31.10 k8s.io/klog v1.0.0 - k8s.io/klog/v2 v2.130.1 + k8s.io/klog/v2 v2.140.0 k8s.io/kube-aggregator v0.31.10 k8s.io/kube-openapi v0.0.0-20250610211856-8b98d1ed966a k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 diff --git a/go.sum b/go.sum index 304a6aa2..eb39ad34 100644 --- a/go.sum +++ b/go.sum @@ -309,8 +309,8 @@ k8s.io/component-base v0.31.10 h1:8daIQBYMhcnuXMD1otGkjpx4d4b0UIcg18xieLTAGA0= k8s.io/component-base v0.31.10/go.mod h1:qoSFFg2SO854XgeCJwFL/LPY/oJU1vqJHhNCEgI6xhA= k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= -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/kms v0.31.10 h1:jD/+hMQ8WT4ht419sXNs1u4dqeJidG34rFcnb2nP6CM= k8s.io/kms v0.31.10/go.mod h1:OZKwl1fan3n3N5FFxnW5C4V3ygrah/3YXeJWS3O6+94= k8s.io/kube-aggregator v0.31.10 h1:NeqnNYGEpJx8NTN56q48vR1XFyLG/8Rif/5iazNSTwE= diff --git a/pkg/config/args_log.go b/pkg/config/args_log.go index 0007d1cb..27469529 100644 --- a/pkg/config/args_log.go +++ b/pkg/config/args_log.go @@ -27,5 +27,10 @@ import ( func AddLogFlags(set *pflag.FlagSet) { fs := flag.NewFlagSet("", 0) klog.InitFlags(fs) + // Opt into the new klog behavior so that -stderrthreshold is honored even + // when -logtostderr=true (the default). + // Ref: kubernetes/klog#212, kubernetes/klog#432 + _ = fs.Set("legacy_stderr_threshold_behavior", "false") + _ = fs.Set("stderrthreshold", "INFO") set.AddGoFlagSet(fs) } diff --git a/pkg/config/args_log_test.go b/pkg/config/args_log_test.go new file mode 100644 index 00000000..e0bc939a --- /dev/null +++ b/pkg/config/args_log_test.go @@ -0,0 +1,44 @@ +/* +Copyright 2022 The KubeVela Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package config + +import ( + "testing" + + "github.com/spf13/pflag" + "github.com/stretchr/testify/assert" +) + +func TestAddLogFlags(t *testing.T) { + set := pflag.NewFlagSet("test", pflag.ContinueOnError) + AddLogFlags(set) + + // klog flags should be registered + f := set.Lookup("v") + assert.NotNil(t, f, "expected klog -v flag to be registered") + + // legacy_stderr_threshold_behavior should be opted out + legacy := set.Lookup("legacy_stderr_threshold_behavior") + assert.NotNil(t, legacy, "expected legacy_stderr_threshold_behavior flag") + assert.Equal(t, "false", legacy.Value.String()) + + // stderrthreshold should default to INFO + threshold := set.Lookup("stderrthreshold") + assert.NotNil(t, threshold, "expected stderrthreshold flag") + // klog maps INFO to severity 0 + assert.Equal(t, "0", threshold.Value.String()) +}