Skip to content
Open
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
5 changes: 5 additions & 0 deletions cmd/addon-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/args_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
44 changes: 44 additions & 0 deletions pkg/config/args_log_test.go
Original file line number Diff line number Diff line change
@@ -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")
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Apr 27, 2026

Choose a reason for hiding this comment

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

P2: Non-fatal assert.NotNil is followed by unconditional dereference, which can panic and obscure the real assertion failure.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At pkg/config/args_log_test.go, line 36:

<comment>Non-fatal `assert.NotNil` is followed by unconditional dereference, which can panic and obscure the real assertion failure.</comment>

<file context>
@@ -0,0 +1,44 @@
+
+	// 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())
+
</file context>
Fix with Cubic

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())
}
Loading