Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helm template --namespace should set the 'metadata.namespace' field on created resources #3553

Closed
munnerz opened this issue Feb 22, 2018 · 41 comments
Labels

Comments

@munnerz
Copy link
Contributor

munnerz commented Feb 22, 2018

I'm currently using helm template to generate static manifests from our authoritative helm chart in the cert-manager project. You can see the script that does this here: https://github.com/jetstack/cert-manager/blob/master/hack/update-deploy-gen.sh.

Currently, despite specifying --namespace, the namespace field is not set on the generated resources. I'm aware that I could deploy with -n namespace, however for a cleaner experience for end-users, it'd be preferable to not have to include this step.

In the meantime, I will likely add namespace: {{ .Release.Namespace }} to each of my namespaced resources, however it'd be ideal if helm template itself could do this (as from what I understand, the best practice with helm chart is to not include the metadata.namespace field at all, and let helm/tiller manage namespace selection).

Is this the recommended approach, and would it be conceivable to change the behaviour of helm template to do this for us automatically?

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
/remove-lifecycle stale

@bbetter173
Copy link

Please don't close this issue - it impacts us quite heavily as having to fork charts just to add the namespace metadata is arduous.

@deltaroe
Copy link

deltaroe commented Aug 31, 2018

It's a hack, but you can pass the output of helm template through this to add the namespace. https://gist.github.com/deltaroe/63afd52ba84274ed5b86ba9b0c357e8f

helm template -f values.yaml -n NAME CHART | ./add-ns.py cool-namespace | kubectl apply -f-

@daviddyball
Copy link

Would it be safe to assume that this issue won't be looked into until Helm 3 is released?

@Tronix117
Copy link

Using the hack of @deltaroe don't forget to pass --namespace cool-namespace to the helm template too. Some charts providers have started adding the namespace key themselves due to this issue.

eh-am added a commit to eh-am/charts that referenced this issue May 16, 2019
this is needed for when helm is used purely as a templating tool,
since helm template does not add the namespace
helm/helm#3553

Signed-off-by: eduardo aleixo <eduardoaleixomartins@gmail.com>
eh-am added a commit to eh-am/charts that referenced this issue May 16, 2019
this is needed for when helm is used purely as a templating tool,
since helm template does not add the namespace
helm/helm#3553

Signed-off-by: eduardo aleixo <eduardoaleixomartins@gmail.com>
eh-am added a commit to eh-am/charts that referenced this issue May 17, 2019
this is needed for when helm is used purely as a templating tool,
since helm template does not add the namespace
helm/helm#3553

Signed-off-by: eduardo aleixo <eduardoaleixomartins@gmail.com>
amine7536 pushed a commit to amine7536/charts that referenced this issue May 21, 2019
this is needed for when helm is used purely as a templating tool,
since helm template does not add the namespace
helm/helm#3553

Signed-off-by: eduardo aleixo <eduardoaleixomartins@gmail.com>
eh-am added a commit to eh-am/charts that referenced this issue May 21, 2019
this is needed for when helm is used purely as a templating tool,
since helm template does not add the namespace
helm/helm#3553

Signed-off-by: eduardo aleixo <eduardoaleixomartins@gmail.com>
eh-am added a commit to eh-am/charts that referenced this issue May 21, 2019
this is needed for when helm is used purely as a templating tool,
since helm template does not add the namespace
helm/helm#3553

Signed-off-by: eduardo aleixo <eduardoaleixomartins@gmail.com>
@deefdragon
Copy link

I WAS setting up a process to store rendered templates versioned such that I can validate any changes to the values as well as any changes to the helm in one location. The fact that namespaces are not saved in the templates took me several hours to debug and working with helm was a waste of my time.

This was closed for a ridiculous reason. The yaml files output from helm template should represent the EXACT state that helm install would create. Not "the state that would be applied if kubectl uses the same arguments". Otherwise whats the point of having those options on template to begin with? Or the point of templating at all? They are literally irrelevant for my use case now, and I have to redesign my process.

Either add them to the template, or remove them as arguments (crash if set). I'm for the former because that option makes actual sense as to what templates are supposed to do, but at least pick one.

@MichaelHindley
Copy link

We are running into major headaches with helm template not working as expected with diverse namespace parameters. In our case, we have a GitOps pattern and we render out helm templates in order to perform reconciliation, the issue is that the metadata.namespace field is not respecting the namespace parameter as I think we and many others would find intuitive, mostly because it differs from helm install but it does so on locally provided input, not on cluster data.

@mlkmhd
Copy link

mlkmhd commented Aug 29, 2022

I did it with yq and kubectl-slice tools:

#!/bin/bash

helm template -n $KUBERNETES_NAMESPACE myproject ./helm-chart > all.yaml

kubectl-slice --input-file=all.yaml --output-dir=manifests

for filename in manifests/*; do
    yq -i --yaml-output ".metadata |= ({namespace: \"$KUBERNETES_NAMESPACE\"} + .)" $filename
done

rquitales added a commit to pulumi/pulumi-kubernetes that referenced this issue Dec 12, 2023
…mespace (#2655)

### Proposed changes

This pull request modifies the `GetResource` Go method for the Helm
Chart resource. Previously, when a resource was deployed to the default
namespace, the `default` namespace was always omitted from the resource
lookup key. However, in cases where the namespace is explicitly defined
in the Helm chart template, the `default` namespace was inadvertently
excluded from the resource lookup key despite it being needed. This
behavior in Helm is documented in the upstream issue:
helm/helm#3553.

**Changes Made:**
- Implemented a fallback mechanism to include the `default` namespace in
the resource lookup key when necessary for the `GetResource` method.

**Test Added:**
- Added a test (`ChartGetResource`) to verify the `GetResource` method
for both types of Helm charts—those with the explicitly defined default
namespace and those without.

**Verification:**
- Verified that the modified `GetResource` method successfully handles
scenarios where the namespace is explicitly defined in the Helm chart
template.
- Confirmed that the added test covers both types of Helm charts and
fails when the fallback logic is reverted.

### Related issues (optional)

Fixes: #2638
rquitales added a commit to pulumi/pulumi-kubernetes that referenced this issue Dec 15, 2023
…mespace (#2655)

This pull request modifies the `GetResource` Go method for the Helm
Chart resource. Previously, when a resource was deployed to the default
namespace, the `default` namespace was always omitted from the resource
lookup key. However, in cases where the namespace is explicitly defined
in the Helm chart template, the `default` namespace was inadvertently
excluded from the resource lookup key despite it being needed. This
behavior in Helm is documented in the upstream issue:
helm/helm#3553.

**Changes Made:**
- Implemented a fallback mechanism to include the `default` namespace in
the resource lookup key when necessary for the `GetResource` method.

**Test Added:**
- Added a test (`ChartGetResource`) to verify the `GetResource` method
for both types of Helm charts—those with the explicitly defined default
namespace and those without.

**Verification:**
- Verified that the modified `GetResource` method successfully handles
scenarios where the namespace is explicitly defined in the Helm chart
template.
- Confirmed that the added test covers both types of Helm charts and
fails when the fallback logic is reverted.

Fixes: #2638
@bernardgut
Copy link

why is this closed ? The documentation makes it seem like helm template and helm install are functionally equivalent while clearly, they are not.

This is clearly not a "feature" : Countless downstream projects and users are wasting time because of this, as you can obviously see with the trail of links pointing to this issue above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests