diff --git a/deploy/klusterlet/chart/klusterlet/templates/agent-namespace.yaml b/deploy/klusterlet/chart/klusterlet/templates/agent-namespace.yaml index 8840d3243..0b5453e69 100644 --- a/deploy/klusterlet/chart/klusterlet/templates/agent-namespace.yaml +++ b/deploy/klusterlet/chart/klusterlet/templates/agent-namespace.yaml @@ -1,3 +1,5 @@ +{{- $generatedNamespace := include "agentNamespace" . }} +{{- if ne $generatedNamespace .Release.Namespace }} {{- if or .Values.bootstrapHubKubeConfig .Values.externalManagedKubeConfig .Values.multiHubBootstrapHubKubeConfigs }} apiVersion: v1 kind: Namespace @@ -6,3 +8,4 @@ metadata: workload.openshift.io/allowed: "management" name: "{{ template "agentNamespace" . }}" {{- end }} +{{- end }} diff --git a/deploy/klusterlet/chart/klusterlet/templates/image_pull_secret.yaml b/deploy/klusterlet/chart/klusterlet/templates/image_pull_secret.yaml index db736edc1..3c6596799 100644 --- a/deploy/klusterlet/chart/klusterlet/templates/image_pull_secret.yaml +++ b/deploy/klusterlet/chart/klusterlet/templates/image_pull_secret.yaml @@ -1,4 +1,3 @@ -{{- if not .Values.noOperator }} {{- if .Values.images.imageCredentials.createImageCredentials }} apiVersion: v1 kind: Secret @@ -11,4 +10,3 @@ type: kubernetes.io/dockerconfigjson data: .dockerconfigjson: {{ template "imagePullSecret" . }} {{- end }} -{{- end }} diff --git a/pkg/operator/helpers/chart/render_test.go b/pkg/operator/helpers/chart/render_test.go index 37c291535..7087bdddc 100644 --- a/pkg/operator/helpers/chart/render_test.go +++ b/pkg/operator/helpers/chart/render_test.go @@ -326,6 +326,27 @@ func TestKlusterletConfig(t *testing.T) { }, expectedObjCnt: 1, }, + { + name: "noOperator with image pull secret", + namespace: "ocm", + chartConfig: func() *KlusterletChartConfig { + config := NewDefaultKlusterletChartConfig() + config.NoOperator = true + config.Klusterlet.Name = "klusterlet2" + config.Klusterlet.Namespace = "open-cluster-management-test" + config.Klusterlet.ClusterName = "testCluster" + config.Images = ImagesConfig{ + ImageCredentials: ImageCredentials{ + CreateImageCredentials: true, + UserName: "test", + Password: "test", + }, + } + return config + }, + + expectedObjCnt: 2, + }, { name: "create namespace", namespace: "open-cluster-management", @@ -338,6 +359,33 @@ func TestKlusterletConfig(t *testing.T) { }, expectedObjCnt: 6, }, + { + name: "create namespace with bootstrap secret", + namespace: "open-cluster-management", + chartConfig: func() *KlusterletChartConfig { + config := NewDefaultKlusterletChartConfig() + config.Klusterlet.ClusterName = "testCluster" + config.Klusterlet.Mode = operatorv1.InstallModeSingleton + config.CreateNamespace = true + config.BootstrapHubKubeConfig = "kubeconfig" + + return config + }, + expectedObjCnt: 8, + }, + { + name: "create namespace with bootstrap secret and release.Namespace is the agent namespace", + namespace: "open-cluster-management-agent", + chartConfig: func() *KlusterletChartConfig { + config := NewDefaultKlusterletChartConfig() + config.Klusterlet.ClusterName = "testCluster" + config.Klusterlet.Mode = operatorv1.InstallModeSingleton + config.CreateNamespace = true + config.BootstrapHubKubeConfig = "kubeconfig" + return config + }, + expectedObjCnt: 7, + }, } for _, c := range cases {