-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Comments
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Please don't close this issue - it impacts us quite heavily as having to fork charts just to add the namespace metadata is arduous. |
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
|
Would it be safe to assume that this issue won't be looked into until Helm 3 is released? |
Using the hack of @deltaroe don't forget to pass |
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>
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>
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>
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>
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>
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>
We are running into major headaches with |
I did it with
|
…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
…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
why is this closed ? The documentation makes it seem like 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. |
It also affects the command helm install --dry-run --debug --generate-name --namespace foo . workaround to generate the correct manifest using NAMESPACE=foo
HELM_CHART=.
helm template --generate-name --namespace "${NAMESPACE}" "${HELM_CHART}"|kubectl apply -n "${NAMESPACE}" --dry-run=client --output=yaml -f - | python -c "import sys, yaml; print('---\n'.join(yaml.safe_dump(item) for item in yaml.safe_load(sys.stdin)['items']))" |
oddly it is working when you run it on a remote chart like this:
but not, if you run it on a local chart |
Pretty sure this used to work but now it seems broken. |
TLDR: If the namespace doesnt get set then your chart is badly constructed, so add in I was under the impression "helm template --namespace abc123" would auto-magically add in "namespace: abc123" into my charts, however this isn't the case, you need to construct the chart correctly. The Redis example you have highlighted has a helper template located in the bitnami-common library chart to add in the Namespace correctly; {{/*
Allow the release namespace to be overridden for multi-namespace deployments in combined charts.
*/}}
{{- define "common.names.namespace" -}}
{{- default .Release.Namespace .Values.namespaceOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}} The above helper ensures you refer to the .Release.Namespace or other default values to set the namespace as required, usage in the Redis chart is as follows; {{- if (include "redis.createConfigmap" .) }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ printf "%s-configuration" (include "common.names.fullname" .) }}
namespace: {{ include "common.names.namespace" . | quote }} Note: above tested with 3.14.3 |
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 ifhelm template
itself could do this (as from what I understand, the best practice with helm chart is to not include themetadata.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?The text was updated successfully, but these errors were encountered: