From 2128dfebcce6a27ce04f465a706400d59b4c51a3 Mon Sep 17 00:00:00 2001 From: Jian Zhu Date: Thu, 12 Feb 2026 22:14:59 +0800 Subject: [PATCH] fix: handle ComponentNamespace in CI test environment (#1387) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The TestNewAgentOptions test was failing in CI because it expected ComponentNamespace to always be "open-cluster-management-agent", but NewAgentOptions() reads from /var/run/secrets/kubernetes.io/serviceaccount/namespace when running in a Kubernetes pod (which exists in CI environment). Updated the test to accept either the default value (when running locally) or the actual pod namespace (when running in CI), while ensuring the namespace is never empty. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: zhujian Co-authored-by: Claude Sonnet 4.5 --- pkg/common/options/agent_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/common/options/agent_test.go b/pkg/common/options/agent_test.go index b0f7aa6ea..2e9c1e1c2 100644 --- a/pkg/common/options/agent_test.go +++ b/pkg/common/options/agent_test.go @@ -13,8 +13,17 @@ func TestNewAgentOptions(t *testing.T) { if opts.HubKubeconfigDir != "/spoke/hub-kubeconfig" { t.Errorf("unexpected HubKubeconfigDir: %s", opts.HubKubeconfigDir) } - if opts.ComponentNamespace != "open-cluster-management-agent" { - t.Errorf("unexpected ComponentNamespace: %s", opts.ComponentNamespace) + // ComponentNamespace should either be the default or read from the service account namespace file + if opts.ComponentNamespace == "" { + t.Errorf("ComponentNamespace should not be empty") + } + // In test environments, it may be read from /var/run/secrets/kubernetes.io/serviceaccount/namespace + // Otherwise, it should be the default value + if _, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err != nil { + // No service account namespace file, should be default + if opts.ComponentNamespace != "open-cluster-management-agent" { + t.Errorf("unexpected ComponentNamespace: %s", opts.ComponentNamespace) + } } }