What happened?
When using Kustomize with Helm charts, the namespace defined at the top level in the kustomization.yaml file is not correctly propagated to the helmCharts releases. As a result, the generated YAML files contains inconsistent values.
kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
helmGlobals:
chartHome: ./charts
namespace: the-actual-namespace # <- defines namespace for all resources
helmCharts:
- name: service
releaseName: service
valuesFile: values.yaml
Helm Chart Template
apiVersion: v1
kind: Service
metadata:
name: the-bug
namespace: {{ .Release.Namespace }}
annotations:
this-service-is-deployed-in-namespace: {{ .Release.Namespace }}
Result
$ kustomize build . --enable-helm
apiVersion: v1
kind: Service
metadata:
annotations:
this-service-is-deployed-in-namespace: default # <- {{ .Release.Namespace }} still points to "default"
name: the-bug
namespace: the-actual-namespace # <- Namespace overwritten by Kustomization to the correct value
This inconsistency can cause issues when deploying resources, such as Bitnami Minio Chart, which relies on the {{ .Release.Namespace }} to dynamically create the service URL.
https://github.com/bitnami/charts/blob/e8999fedbd8e35c96099aa44d3ca4ea947bfbe22/bitnami/minio/templates/distributed/statefulset.yaml#L150
What did you expect to happen?
I expected that the namespace defined in the top level of the kustomization.yaml file would be passed down to all helmCharts releases.
When a Helm chart entry already specifies a namespace, that namespace should take precedence.
How can we reproduce it (as minimally and precisely as possible)?
Repository to reproduce it is available here: https://github.com/Skaronator/kustomize-namespace-bug
$ tree
.
├── charts
│ └── service
│ ├── Chart.yaml
│ ├── templates
│ │ └── service.yaml
│ └── values.yaml
├── kustomization.yaml
├── README.md
└── values.yaml
4 directories, 6 files
# ./kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
helmGlobals:
chartHome: ./charts
namespace: the-actual-namespace # <- defines namespace for all resources
helmCharts:
- name: service
releaseName: service
valuesFile: values.yaml
# ./charts/service/Chart.yaml
apiVersion: v2
name: service
description: A Helm chart for Kubernetes
type: application
version: 1.0.0
appVersion: "1.0.0"
# ./charts/service/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: the-bug
namespace: {{ .Release.Namespace }}
annotations:
this-service-is-deployed-in-namespace: {{ .Release.Namespace }}
Expected output
$ kustomize build . --enable-helm
apiVersion: v1
kind: Service
metadata:
annotations:
this-service-is-deployed-in-namespace: the-actual-namespace # <- {{ .Release.Namespace }} should be correctly set
name: the-bug
namespace: the-actual-namespace # <- Namespace overwritten by Kustomization to the correct value
Actual output
$ kustomize build . --enable-helm
apiVersion: v1
kind: Service
metadata:
annotations:
this-service-is-deployed-in-namespace: default # <- {{ .Release.Namespace }} still points to "default"
name: the-bug
namespace: the-actual-namespace # <- Namespace overwritten by Kustomization to the correct value
Kustomize version
v5.3.0
Operating system
Linux
What happened?
When using Kustomize with Helm charts, the namespace defined at the top level in the kustomization.yaml file is not correctly propagated to the helmCharts releases. As a result, the generated YAML files contains inconsistent values.
kustomization.yaml
Helm Chart Template
Result
This inconsistency can cause issues when deploying resources, such as Bitnami Minio Chart, which relies on the {{ .Release.Namespace }} to dynamically create the service URL.
https://github.com/bitnami/charts/blob/e8999fedbd8e35c96099aa44d3ca4ea947bfbe22/bitnami/minio/templates/distributed/statefulset.yaml#L150
What did you expect to happen?
I expected that the namespace defined in the top level of the kustomization.yaml file would be passed down to all helmCharts releases.
When a Helm chart entry already specifies a namespace, that namespace should take precedence.
How can we reproduce it (as minimally and precisely as possible)?
Repository to reproduce it is available here: https://github.com/Skaronator/kustomize-namespace-bug
Expected output
Actual output
Kustomize version
v5.3.0
Operating system
Linux