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 upgrade does not re-create namespace when it is gone #2013

Closed
peay opened this issue Feb 23, 2017 · 34 comments
Closed

helm upgrade does not re-create namespace when it is gone #2013

peay opened this issue Feb 23, 2017 · 34 comments

Comments

@peay
Copy link
Contributor

peay commented Feb 23, 2017

When the namespace of a release had been deleted, upgrade fails:

Error: UPGRADE FAILED: failed to create resource: namespaces "xxxxx" not found

This is arguably a special situation, but I would expect helm to re-create the "resources that do not already exist" (https://github.com/kubernetes/helm/blob/master/pkg/kube/client.go#L201), including namespaces.

How about calling ensureNamespace there in Update, as is done in Create? I can try and send a PR for this.

@technosophos
Copy link
Member

Is the namespace explicitly declared in the chart?

@peay
Copy link
Contributor Author

peay commented Feb 23, 2017

Good point, it is not. This is still slightly inconsistent with the behavior of install though, but that is a good workaround.

@technosophos
Copy link
Member

You're right. Just trying to figure out how best to re-create the problem. Thanks!

@technosophos technosophos added this to the 2.4.0-Triage milestone Feb 23, 2017
@peay
Copy link
Contributor Author

peay commented Feb 23, 2017

Actually, I am wondering if including the namespace in the chart necessarily works: is it guaranteed to be applied first? I guess if it is not, we could still get the issue above.

@sheerun
Copy link
Contributor

sheerun commented Mar 24, 2017

The same for me helm upgrade -i RELEASE CHART --namespace XXX throws "Error: UPGRADE FAILED: failed to create resource: namespaces "XXX" not found" even though helm install --name RELEASE CHART --namespace XXX succeeds. It is indeed inconsistent.

@sheerun
Copy link
Contributor

sheerun commented Mar 24, 2017

Another issue, when I crated namespace object like so:

apiVersion: v1
kind: Namespace
metadata:
  name: {{ .Release.Namespace }}

and executed helm upgrade -i RELEASE CHART --namespace XXX, I get following error:

Release "RELEASE" does not exist. Installing it now.
Error: release RELEASE failed: namespaces "XXX" already exists

Only the second time I run this command, deployment succeeds..

@sheerun
Copy link
Contributor

sheerun commented Mar 24, 2017

My workaround: Add namespace: {{ .Values.namespace }} to each resource and don't use --namespace flag

In helm list it looks like it's deployed under default namespace though.

@technosophos Isn't it weird that even Helm is supposed to work on global level, there are "namespaces" as first-class concept in both cli and helm list output? Wouldn't it make more sense to drop namespace concept from helm cli at all and allow to override namespaces of all resources in some way in templates? Like:

override:
  metadata:
    namespace: {{ .Values.namespace }}

@jayme-github
Copy link

/cc @tback @wjkohnen

@nambrot
Copy link

nambrot commented Aug 15, 2017

Just wanted to say that I also just ran into this. I expected helm upgrade --namespace namespace to install my charts into the specific namespace just like install does.

Note that in my situation, the namespace already exists and it still doesnt install in the namespace

@ptagr
Copy link

ptagr commented Sep 7, 2017

+1 just ran into this just now!

@Morriz
Copy link

Morriz commented Oct 3, 2017

yeah...why is it not using the specified namespace on upgrade? anybody can explain?

@ultimateboy
Copy link

The easiest way I know how to reproduce the issue is:

$ helm install stable/mongodb --name=mongodb --namespace=mongodb
$ helm delete mongodb
$ kubectl delete ns mongodb
$ helm upgrade --install mongodb stable/mongodb --set replicaCount=2
Error: UPGRADE FAILED: failed to create resource: namespaces "mongodb" not found

@technosophos
Copy link
Member

Likely, it is querying the namespace to prepare diffs, and the namespace doesn't exist. So no resource diffs can be generated. And it dies with an error.

On an install, we don't have to perform any queries on a namespace until after the namespace is created.

BugRoger added a commit to sapcc/kubernikus that referenced this issue Nov 13, 2017
@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.

Prevent issues from auto-closing with an /lifecycle frozen comment.

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

@waseem-h
Copy link

/remove-lifecycle stale

@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

@olemarkus
Copy link

Just experienced the same issue.

@metral
Copy link

metral commented May 24, 2018

/remove-lifecycle stale

@mmack
Copy link

mmack commented May 25, 2018

Same issue here... It makes helm practically unusable if one tries to create namespaces and default resources (like default ingress per NS, default http backends) for "customers". If you add a new NS to the config - the upgrade fails, so does a install. Kinda stalled there...

@rahulakash
Copy link

Hi,

We are still seeing this issue with Helm v2.9.1. This can be reproduced like @ultimateboy has mentioned above.

Thank you.

@bacongobbler
Copy link
Member

re-labeling this as a feature request, since we've never supported re-creating the namespace on a helm upgrade. We are busy working on Helm 3 as well as general maintenance on Helm 2, but if someone wants to work on this, contributions are welcome!

@rahulakash
Copy link

Thank you @bacongobbler. Just for clarification, I understand if helm upgrade does not support re-creating namespaces. But, we use the --install flag along with upgrade by default helm upgrade --install and it would be nice if namespaces are also re-created in that case (when --install flag is used).

@technosophos
Copy link
Member

Oh, that is interesting... I thought --install walked the entire installation process if Tiller detected that the given chart was a new one. Or is this only happening when the release walks the upgrade path?

@mathieu-benoit
Copy link

mathieu-benoit commented Sep 6, 2018

FYI, to be able to reproduce easily the original issue When the namespace of a release had been deleted, upgrade fails:

$ helm install stable/mongodb --name=mongodb --namespace=mongodb
$ kubectl delete ns mongodb
$ helm upgrade --install mongodb stable/mongodb --namespace=mongodb
Error: UPGRADE FAILED: failed to create resource: namespaces "mongodb" not found

Note: same error message without the --install.

@mathieu-benoit
Copy link

mathieu-benoit commented Sep 6, 2018

@ultimateboy, I tried yours explained here #2013 (comment), but you are missing a --purge for the helm delete and a --namespace=mongodb for the helm upgrade. Other than that, I was able to make your script working. Thoughts?

@mathieu-benoit
Copy link

FYI, I just opened an associated PR #4600, but still need some guidance around this open question:
Do we have to take into account the --install parameter? Or do that for any helm upgrade if the --namespace is not empty? Or both?

@RehanSaeed
Copy link

Is it recommended practice to add a namespace.yml file like so:

apiVersion: v1
kind: Namespace
metadata:
  name: {{ .Release.Namespace }}

@aelbarkani
Copy link

any updates about this bug ?

@2ZZ
Copy link

2ZZ commented Apr 9, 2019

also seeing this issue

@luisdavim
Copy link
Contributor

luisdavim commented May 8, 2019

helm upgrade --install should have the same behaviour as helm install and create the namespace if missing. So I think this is actually a bug and not a feature request.

@bacongobbler
Copy link
Member

bacongobbler commented May 8, 2019

For context, helm upgrade --install just checks the release history for an existing release. If it's not present, perform a helm install, otherwise do a helm upgrade. Hope that helps clear things up.

In the install case, helm upgrade --install will create the namespace as expected. The issue here is the problem where helm upgrade will not re-create the namespace if it was deleted out-of-band. It applies to both helm upgrade and helm upgrade --install because the code paths are identical.

It is a feature request; helm upgrade has never re-created the namespace if it was deleted out-of-band. This is a feature request for Helm to re-create resources from scratch if they were purged with kubectl delete.

@luisdavim
Copy link
Contributor

luisdavim commented May 8, 2019

In my experience that is not what happens. Today I was using helm upgrade --install and got an error saying the namespace doesn't exist. This was a new installation without previous releases.

@luisdavim
Copy link
Contributor

any updates on this?

@bacongobbler
Copy link
Member

Closing. Helm 3 no longer creates the namespace as part of helm install (see #5753 for background context on why we changed this behaviour - this issue being one of those reasons). Thanks.

MichaelMorrisEst pushed a commit to Nordix/helm that referenced this issue Nov 17, 2023
helm-diff 3.3.1 adds a new option `HELM_DIFF_THREE_WAY_MERGE=true` which enables the use of there-way merge for diff, which is expected to fix helm#2013
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