From bd7b8af6ada6d03f6ce6670037fd8c3617ca35ba Mon Sep 17 00:00:00 2001 From: Antoine Jouve Date: Wed, 26 Mar 2025 17:27:50 +0100 Subject: [PATCH 1/3] feat: allow overriding the namespace the chart deploys to Signed-off-by: Antoine Jouve --- charts/portworx/templates/_helpers.tpl | 6 +++++- charts/portworx/values.yaml | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/charts/portworx/templates/_helpers.tpl b/charts/portworx/templates/_helpers.tpl index 21b3623b4..e0421e5db 100644 --- a/charts/portworx/templates/_helpers.tpl +++ b/charts/portworx/templates/_helpers.tpl @@ -226,7 +226,11 @@ Generate a random token for storage provisioning {{- if (eq "default" .Release.Namespace) -}} {{- printf "portworx" -}} {{- else -}} - {{- printf "%s" .Release.Namespace -}} + {{- if (.Values.namespaceOverride) -}} + {{- printf "%s" .Values.namespaceOverride -}} + {{- else -}} + {{- printf "%s" .Release.Namespace -}} + {{- end -}} {{- end -}} {{- end -}} {{- end -}} diff --git a/charts/portworx/values.yaml b/charts/portworx/values.yaml index f9591314a..205843c20 100644 --- a/charts/portworx/values.yaml +++ b/charts/portworx/values.yaml @@ -3,6 +3,8 @@ deployOperator: true # Deploy the Portworx operator deployCluster: true # Deploy the Portworx cluster +namespaceOverride: ~ # Override the namespace the chart deploys to + imageVersion: 3.2.2 # Version of the PX Image. pxOperatorImageVersion: 24.2.3 # Version of the PX operator image. @@ -266,4 +268,4 @@ updateStrategy: # where the size of the pod batch is specified through the spec.updateStrategy.rollingUpdate.maxUnavailable flag. autoUpdateComponents: # Indicates the update strategy for the component images - # valid values None,Once,Always \ No newline at end of file + # valid values None,Once,Always From ce3c4aea4d60cf9ca39cf38f292e726b3ecb8080 Mon Sep 17 00:00:00 2001 From: Antoine Jouve Date: Thu, 27 Mar 2025 10:45:18 +0100 Subject: [PATCH 2/3] feat: add test cases Signed-off-by: Antoine Jouve --- charts/portworx/templates/_helpers.tpl | 12 ++++---- .../storagecluster_helm_template_test.go | 7 +++++ .../storagecluster_override_namespace.yaml | 1 + .../storagecluster_override_namespace.yaml | 30 +++++++++++++++++++ 4 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 test/portworx/testValues/storagecluster_override_namespace.yaml create mode 100644 test/portworx/testspec/storagecluster_override_namespace.yaml diff --git a/charts/portworx/templates/_helpers.tpl b/charts/portworx/templates/_helpers.tpl index e0421e5db..05bbdd344 100644 --- a/charts/portworx/templates/_helpers.tpl +++ b/charts/portworx/templates/_helpers.tpl @@ -222,12 +222,12 @@ Generate a random token for storage provisioning {{- define "px.getDeploymentNamespace" -}} -{{- if (.Release.Namespace) -}} - {{- if (eq "default" .Release.Namespace) -}} - {{- printf "portworx" -}} - {{- else -}} - {{- if (.Values.namespaceOverride) -}} - {{- printf "%s" .Values.namespaceOverride -}} +{{- if not .Values.namespaceOverride | empty -}} + {{- printf "%s" .Values.namespaceOverride -}} +{{- else -}} + {{- if (.Release.Namespace) -}} + {{- if (eq "default" .Release.Namespace) -}} + {{- printf "portworx" -}} {{- else -}} {{- printf "%s" .Release.Namespace -}} {{- end -}} diff --git a/test/portworx/storagecluster_helm_template_test.go b/test/portworx/storagecluster_helm_template_test.go index 37fd81ab7..9ee8d20b3 100644 --- a/test/portworx/storagecluster_helm_template_test.go +++ b/test/portworx/storagecluster_helm_template_test.go @@ -53,6 +53,13 @@ func TestStorageClusterHelmTemplate(t *testing.T) { ValuesFiles: []string{"./testValues/storagecluster_custom_registry.yaml"}, }, }, + { + name: "TestOverrideNamespace", + resultFileName: "storagecluster_override_namespace.yaml", + helmOption: &helm.Options{ + ValuesFiles: []string{"./testValues/storagecluster_override_namespace.yaml"}, + }, + }, { name: "TestExternalETCD", resultFileName: "storagecluster_external_etcd.yaml", diff --git a/test/portworx/testValues/storagecluster_override_namespace.yaml b/test/portworx/testValues/storagecluster_override_namespace.yaml new file mode 100644 index 000000000..d781277c9 --- /dev/null +++ b/test/portworx/testValues/storagecluster_override_namespace.yaml @@ -0,0 +1 @@ +namespaceOverride: custom-namespace diff --git a/test/portworx/testspec/storagecluster_override_namespace.yaml b/test/portworx/testspec/storagecluster_override_namespace.yaml new file mode 100644 index 000000000..fac57e2a1 --- /dev/null +++ b/test/portworx/testspec/storagecluster_override_namespace.yaml @@ -0,0 +1,30 @@ +kind: StorageCluster +apiVersion: core.libopenstorage.org/v1 +metadata: + name: "mycluster" + namespace: custom-namespace + annotations: + labels: + heritage: "Helm" + release: "my-release" + app.kubernetes.io/managed-by: "Helm" + app.kubernetes.io/instance: "my-release" +spec: + image: portworx/oci-monitor:3.2.1.1 + imagePullPolicy: Always + + kvdb: + internal: true + storage: + useAll: true + secretsProvider: k8s + + stork: + enabled: true + monitoring: + telemetry: + enabled: true + csi: + enabled: true + autopilot: + enabled: true From 8ed78e480059d23c4b160ff147f3a464cf1f21bf Mon Sep 17 00:00:00 2001 From: Antoine Jouve Date: Thu, 27 Mar 2025 11:00:19 +0100 Subject: [PATCH 3/3] fix: properly create custom namespace Signed-off-by: Antoine Jouve --- charts/portworx/templates/portworx-k8s-secrets.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/portworx/templates/portworx-k8s-secrets.yaml b/charts/portworx/templates/portworx-k8s-secrets.yaml index f42823c4a..b60095d1e 100644 --- a/charts/portworx/templates/portworx-k8s-secrets.yaml +++ b/charts/portworx/templates/portworx-k8s-secrets.yaml @@ -1,4 +1,4 @@ -{{- if and (eq .Release.Namespace "default") (not (lookup "v1" "Namespace" "portworx" "portworx")) }} +{{- if or (and (eq .Release.Namespace "default") (not (lookup "v1" "Namespace" "portworx" "portworx"))) (not .Values.namespaceOverride | empty)}} apiVersion: v1 kind: Namespace metadata: