Repository navigation
Description
Hi,
Helm raises an error if we try to install with a chart some resources which already exist in our cluster.
According to @bacongobbler in #6031, "Helm does not "adopt" existing resources; if a resource exists before it was introduced in the chart, it's considered an error condition, hence the error message".
Some post suggested a workaround with Helm version 2. During the first installation, the release was in a state FAILED, but a second installation of the same chart made the release in
a DEPLOYED state.
With Helm3, it does not work anymore:
$ helm3 install test ./helm-test --debug
install.go:158: [debug] Original chart version: ""
install.go:175: [debug] CHART PATH: [...]
client.go:86: [debug] creating 3 resource(s)
Error: services "service" already exists
helm.go:81: [debug] services "service" already exists
$ helm3 install test ./helm-test --replace --debug
install.go:158: [debug] Original chart version: ""
install.go:175: [debug] CHART PATH: [...]
client.go:86: [debug] creating 3 resource(s)
Error: services "service" already exists
helm.go:81: [debug] services "service" already exists
$ helm3 ls
NAME NAMESPACE REVISION UPDATED STATUS CHART
test default 1 2019-10-02 17:29:13.735401532 -0400 EDT failed helm-test-0.1.0
test default 2 2019-10-02 17:31:05.690696039 -0400 EDT failed helm-test-0.1.0
So this behavior is probably intended, but in this case, how can I merge the k8s resources of an active cluster to a Helm chart? It is suggested to delete the objects and recreate them with Helm, but it is not a realistic option with a running cluster. What is your advice to "adopt" running resources?
Thanks for your support,
JB
$ helm3 version
version.BuildInfo{Version:"v3.0.0-beta.3", GitCommit:"5cb923eecbe80d1ad76399aee234717c11931d9a", GitTreeState:"clean", GoVersion:"go1.12.9"}
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"12+", GitVersion:"v1.12.9-gke.7" [...]}
Server Version: version.Info{Major:"1", Minor:"12+", GitVersion:"v1.12.8-gke.10" [...]}
Cloud Provider/Platform (AKS, GKE, Minikube etc.): GKE
Activity
[-]helm3: [/-][+]helm3: How to adopt existing resources[/+]juborto commentedon Oct 18, 2019
Hi,
to complete my ticket, I tested a little bit more and I found this interesting case. I don't know if it is expected by design.
I have a k8s cluster with only one svc and one deployment installed on it.
The Helm chart I want to install contains the same service and deploy:
Now, I am trying to install the chart
helm-testand as I noted in the first post, it is failing (status failed)If I delete the chart with Helm3, the two resources present on my cluster are deleted, even if apparently Helm3 does not "adopt" existing resources
I know that this feature (by the way, I don't know if it is a feature) was present with Helm2, but it seems dangerous.
@bacongobbler: What is your opinion?
Thanks,
JB
marckhouzam commentedon Oct 19, 2019
There are some details about this deleting of resources in #6407.
Personally I also think that deleting resources not created by helm doesn't sound right.
sharedprophet commentedon Nov 22, 2019
IMO there needs to be some way to recover control of resources. When I try to do an install and it times out, even with
--atomic, it doesn't remove the resources deployed but also doesn't add them to the helm history, so they can no longer be controlled by helm at all. Adding--replacedidn't help. Even manually deleting everything that was deployed didn't stop it giving me theError: cannot re-use a name that is still in usemessage. For now I have to revert to helm 2...bacongobbler commentedon Nov 22, 2019
FYI, #6542 fixed the issue referenced earlier at #6561 (comment). Please upgrade to a newer version of Helm 3 to get the fix. It was released in 3.0.0-beta.4.
sharedprophet commentedon Nov 22, 2019
I was experiencing this with 3.0.0 final release.
bacongobbler commentedon Nov 22, 2019
Sorry for the confusion! I was replying to another comment referencing a different issue, not your comment (and the original issue raised in this ticket). Carry on. :)
poelzi commentedon May 28, 2020
It's not about deleting but replacing objects in place that already exist. If you have a running system you have developed without helm and later want to use helm, this functionality is critical. I find it super annoying to run helm dozens of times just to get very time a new object name back, which I then have to delete, just to install the same objects, but now with helm. Seriously, don't try to tell the admin what he can't do. If I set a propper switch, just do it.
bacongobbler commentedon May 28, 2020
@poelzi and @sharedprophet, if I understand your use cases correctly, you are concerned about resources that were orphaned by a release can no longer be recovered once the release history has been purged. If that's the case, #7649 should help in your situations, as it marks resources that are being deployed by a particular release. If an install fails, Helm should now understand that this particular release has ownership of that resource, and it should be able to recover from that state. This was made available in Helm 3.2. Give that a shot and see if that handles your use case.
What @marckhouzam is implying (and correct me if I'm wrong here, @marckhouzam) is he's concerned about whether a chart should be granted the ability to adopt resources the chart did not previously own. It is a fair point; how can we predict that the install will work if the chart has no knowledge about the resource at all? How will rollbacks work? There are a lot of edge cases to consider there, and I'm not sure the OP has considered those cases yet.
marckhouzam commentedon May 29, 2020
Thank you @bacongobbler. That is correct. Specifically, I was agreeing with the OP's second comment which showed side-effects of adoption.
But even more generally, say I'm a user of a shared cluster (or shared namespace) and I installed something without helm. Then someone else comes along and installs a helm chart that happens to use the same naming terminology as some of my stuff. If helm just adopts some of my resources I will have problems.
So as @bacongobbler says, adoption has to be thoroughly thought out before helm can support it. Flags, warnings, explicitly specifying what needs to be adopted... I believe there is one (or maybe even two) PR to move this along.
prashantkalkar commentedon Jul 14, 2020
@poelzi @bacongobbler @marckhouzam Is there any work going on (or planned) for adopting existing resources in a helm chart
Also, If any workaround exists for this, please mentioned it here.
antonsmelyanskiy commentedon Jul 21, 2020
Putting labels on all existing resources is super annoying, i would rather have an overwrite switch that just adopts everything.
As it stands now, it is more feasible to just delete whole namespace before upgrading to helm 3.
scarby commentedon Sep 4, 2020
it also seems that adding labels to resources is not a good solution either due to the 3 way merge (noticing that certain fields are not getting removed when they need to be - assuming they have changed between helm and non-helm versions)
octplane commentedon Oct 14, 2020
We have this very issue: "adopted" CRD instances (using labels) show a discrepancy between the release metadata and the cluster state: "install" does not reapply the full state of the CRD on the cluster and assume that the existing object has the correct manifest. It then saves the manifest in the metadata and leave the CRD in its previous state.
We are trying to work around the issue by forcing the cluster resource to match its manifest definition before we trigger install on an "adopted" resource. The other solution would be to build a fake release metadata object so that Helm can "upgrade" the resource instead of installing it.
github-actions commentedon Jan 13, 2021
This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.
abryant-hv commentedon Mar 18, 2021
We hit the same issue with adopting existing resources: after "helm install" the resource remains unchanged... the version from the helm chart does not take effect. The workaround we found was to then also call "helm upgrade --force" with the same chart version, which forces the resources to be recreated correctly.
ashtonian commentedon Nov 16, 2021
can't tell if this can be done or if stale-bot closed this?