From f710c02fdb50e42ed7a32dc84a7ea7e8b6c69232 Mon Sep 17 00:00:00 2001 From: "liheng.zms" Date: Wed, 3 Jan 2024 20:55:52 +0800 Subject: [PATCH] util meta ut Signed-off-by: liheng.zms --- config/manager/manager.yaml | 7 +++++++ pkg/util/meta.go | 2 +- pkg/util/meta_test.go | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 pkg/util/meta_test.go diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index d434240d04..02ec694438 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -6,6 +6,13 @@ metadata: name: system --- apiVersion: v1 +kind: Namespace +metadata: + labels: + control-plane: controller-manager + name: kruise-daemon-config +--- +apiVersion: v1 kind: ServiceAccount metadata: name: manager diff --git a/pkg/util/meta.go b/pkg/util/meta.go index f1df723e1e..9690d81c89 100644 --- a/pkg/util/meta.go +++ b/pkg/util/meta.go @@ -1,5 +1,5 @@ /* -Copyright 2021. +Copyright 2022 The Kruise Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/util/meta_test.go b/pkg/util/meta_test.go new file mode 100644 index 0000000000..65f9cff1f0 --- /dev/null +++ b/pkg/util/meta_test.go @@ -0,0 +1,39 @@ +/* +Copyright 2022 The Kruise 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 util + +import ( + "os" + "testing" +) + +func TestMetaGetNamespace(t *testing.T) { + if GetKruiseNamespace() != "kruise-system" { + t.Fatalf("expect(kruise-system), but get(%s)", GetKruiseNamespace()) + } + _ = os.Setenv("POD_NAMESPACE", "test") + if GetKruiseNamespace() != "test" { + t.Fatalf("expect(test), but get(%s)", GetKruiseNamespace()) + } + if GetKruiseDaemonConfigNamespace() != "kruise-daemon-config" { + t.Fatalf("expect(kruise-daemon-config), but get(%s)", GetKruiseDaemonConfigNamespace()) + } + _ = os.Setenv("KRUISE_DAEMON_CONFIG_NS", "test") + if GetKruiseDaemonConfigNamespace() != "test" { + t.Fatalf("expect(test), but get(%s)", GetKruiseDaemonConfigNamespace()) + } +}