Overlay namespace not overriding HelmChartInflationGenerator output when Helm templates specify namespace (since Kustomize v5.8)
kind/bugneeds-triage
### What happened?
After upgrading Kustomize from v5.4.1 to v5.8.1, we observed a change in how namespaces are applied to resources generated using HelmChartInflationGenerator.
In our repository we deploy multiple environments within the same Kubernetes cluster, so namespaces differ per environment. For example:
**dev-argo-events
stage-argo-events
prod-argo-events**
Because of this setup, the namespace cannot be defined in the base Helm generator. Instead, we rely on the overlay kustomization.yaml to inject the namespace.
**Example overlay configuration:**
**namespace: dev-argo-events
resources:
- ../../base
Observed behavior**
After upgrading to Kustomize v5.8.1, namespaces from the overlay are not consistently applied to resources generated by HelmChartInflationGenerator.
We observed two different behaviors depending on the Helm chart templates:
**1. Charts that do not explicitly define a namespace in templates**
**Example template:
metadata:
name: example**
In this case, the overlay namespace is applied correctly:
namespace: dev-argo-events
**2. Charts that explicitly render a namespace (often default)**
**Example template logic:
metadata:
namespace: {{ .Release.Namespace | default "default" }}**
In this case Helm renders:
namespace: default
and the overlay namespace is not overridden by Kustomize.
Because of this behavior, some applications attempt to deploy resources into the default namespace.
**Current workaround**
1. To avoid this, we had to explicitly define the namespace in the base HelmChartInflationGenerator:
namespace: dev-argo-events
However, this is not ideal for our repository structure because the namespace differs per environment and should normally be injected by overlays.
2. Another workaround would be to move the chartInflator.yaml into each overlay and define the namespace there, for example:
overlays/dev/chartInflator.yaml
overlays/stage/chartInflator.yaml
overlays/prod/chartInflator.yaml
Each overlay would then explicitly set its namespace.
However, this approach leads to duplication of the Helm generator configuration across overlays and breaks the base/overlay separation that we currently rely on in our repository structure.
**Question**
Is this behavior change expected in Kustomize ≥ v5.8?
If so, what is the recommended pattern for repositories where:
Helm generators are defined in base
namespaces differ per environment
namespaces are expected to be injected via overlay kustomization.yaml
Helm templates may explicitly render a namespace
Any guidance would be appreciated.
### What did you expect to happen?
When defining a namespace in the overlay `kustomization.yaml`, the namespace should be applied to all namespace-scoped resources generated by `HelmChartInflationGenerator`, regardless of whether the Helm chart templates explicitly set a namespace or not.
In previous versions of Kustomize (e.g. v5.4.1), the namespace defined in the overlay was applied correctly to Helm-generated resources.
Expected output example:
```yaml
metadata:
namespace: dev-argo-events
Instead of:
metadata:
namespace: default
### How can we reproduce it (as minimally and precisely as possible)?
Repository structure
argo-events/
├── base
│ ├── chartInflator.yaml
│ └── kustomization.yaml
└── overlays
├── dev
│ └── kustomization.yaml
├── stage
│ └── kustomization.yaml
└── prod
└── kustomization.yaml
**In our setup, the Helm generator is defined in the base, and the namespace is defined in each overlay.**
**Example overlay configuration:**
```yaml
namespace: dev-argo-events
resources:
- ../../base
### Expected output
### Actual output
_No response_
### Kustomize version
5.8.1
### Operating system
Linux
1 条评论