Skip to content

fix(helm): Set namespace on templates that does not contain a namespace#6108

Open
Skaronator wants to merge 3 commits intokubernetes-sigs:masterfrom
Skaronator:helm-namespace
Open

fix(helm): Set namespace on templates that does not contain a namespace#6108
Skaronator wants to merge 3 commits intokubernetes-sigs:masterfrom
Skaronator:helm-namespace

Conversation

@Skaronator
Copy link
Copy Markdown
Contributor

@Skaronator Skaronator commented Mar 28, 2026

This PR ensures a namespace is set on Helm-generated resources only if the field is completely missing. This fixes #6058 and fixes #6077 and provides the best of both worlds: Helm charts with pre-defined namespaces remain untouched, while charts lacking a namespace field now function as expected.


The namespace is now set in the following priority:

  1. Value from helm manifest (for charts already containing a namespace field)
  2. Value from helmChart[].namespace (if set)
  3. Value from namespace kustomization.yaml (If Set)

We don't modify any Namespaces relevant fields outside the metadata block. Helm Charts should already take care of that. (e.g. spec field for ClusterRoleBinding)


Checked the issue in #6058 and it is fixed.

/home/niklas/go/bin/kustomize build --enable-helm | grep -A 10 Deployment
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/instance: mariadb-operator
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: mariadb-operator
    app.kubernetes.io/version: 25.10.4
    helm.sh/chart: mariadb-operator-25.10.4
  name: mariadb-operator
  namespace: mariadb-system
spec:

Checked the issue #6077 and it is fixed.

/home/niklas/go/bin/kustomize build --enable-helm | grep -C 5 gh24bh7t8g
apiVersion: v1
data:
  secret: Zm9v
kind: Secret
metadata:
  name: test-secret-gh24bh7t8g
  namespace: cluster
type: Opaque
---
apiVersion: v1
kind: Service
--
      serviceAccountName: release-name-test-chart
      volumes:
      - name: test-secret
        secret:
          defaultMode: 292
          secretName: test-secret-gh24bh7t8g
      - configMap:
          defaultMode: 292
          name: test-config-g46hh6k8tf
        name: test-conf
---

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Mar 28, 2026
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 28, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @Skaronator. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 28, 2026
…erated resources

Track namespace propagation for Helm-generated resources.
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Mar 28, 2026
Comment thread examples/helmNamespace/README.md Outdated
@koba1t
Copy link
Copy Markdown
Member

koba1t commented Mar 28, 2026

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 28, 2026
Copy link
Copy Markdown

@mfredenhagen mfredenhagen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built from source and tested manually 👍

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: davinkevin, mfredenhagen, Skaronator
Once this PR has been reviewed and has the lgtm label, please assign koba1t for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

5 participants