Skip to content

helm3: How to adopt existing resources #6561

Closed

Description

@juborto

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

  1. changed the title [-]helm3: [/-] [+]helm3: How to adopt existing resources[/+] on Oct 2, 2019
  2. added
    v3.x
    on Oct 3, 2019
  3. juborto commented on Oct 18, 2019

    @juborto
    Author

    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.

    $ kubectl get svc
    NAME          TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)     AGE
    kubernetes    ClusterIP   x.x.x.x      <none>        443/TCP     70d
    service       ClusterIP   x.x.x.x      <none>        40000/TCP   4m57s
    $ kubectl get deploy
    NAME          DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
    deployment   1         1         1            1           5m14s
    

    The Helm chart I want to install contains the same service and deploy:

    $ find helm-test/
    helm-test/
    helm-test/Chart.yaml
    helm-test/.helmignore
    helm-test/templates
    helm-test/templates/service.yml
    helm-test/templates/deployment.yml
    helm-test/templates/NOTES.txt
    helm-test/templates/_helpers.tpl
    helm-test/values.yaml
    

    Now, I am trying to install the chart helm-test and as I noted in the first post, it is failing (status failed)

    $ helm3 install test ./helm-test --debug
    install.go:158: [debug] Original chart version: ""
    install.go:175: [debug] CHART PATH: [...]
    client.go:86: [debug] creating 2 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-18 16:55:10.223143572 -0400 EDT	failed	helm-test-0.1.0
    

    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

    $ helm3 delete test
    release "test" uninstalled
    $ helm3 ls
    NAME	NAMESPACE	REVISION	UPDATED	STATUS	CHART
    $ kubectl get svc
    NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
    kubernetes   ClusterIP   x.x.x.x      <none>        443/TCP   70d
    $ kubectl get deploy
    No resources found.
    

    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

    $ 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:"13+", GitVersion:"v1.13.11-dispatcher", GitCommit:"2e298c7e992f83f47af60cf4830b11c7370f6668", GitTreeState:"clean", BuildDate:"2019-09-19T22:20:12Z", GoVersion:"go1.11.13", Compiler:"gc", Platform:"linux/amd64"}
    Server Version: version.Info{Major:"1", Minor:"12+", GitVersion:"v1.12.9-gke.15", GitCommit:"b48a8d693e191192e27c2f807daa51b54d0b0a61", GitTreeState:"clean", BuildDate:"2019-08-12T17:49:30Z", GoVersion:"go1.10.8b4", Compiler:"gc", Platform:"linux/amd64"}
    
  4. marckhouzam commented on Oct 19, 2019

    @marckhouzam
    Member

    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.

  5. sharedprophet commented on Nov 22, 2019

    @sharedprophet

    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 --replace didn't help. Even manually deleting everything that was deployed didn't stop it giving me the Error: cannot re-use a name that is still in use message. For now I have to revert to helm 2...

  6. bacongobbler commented on Nov 22, 2019

    @bacongobbler
    Member

    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.

  7. sharedprophet commented on Nov 22, 2019

    @sharedprophet

    I was experiencing this with 3.0.0 final release.

  8. bacongobbler commented on Nov 22, 2019

    @bacongobbler
    Member

    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. :)

  9. poelzi commented on May 28, 2020

    @poelzi
    Contributor

    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.

    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.

  10. bacongobbler commented on May 28, 2020

    @bacongobbler
    Member

    @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.

  11. marckhouzam commented on May 29, 2020

    @marckhouzam
    Member

    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.

    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.

  12. prashantkalkar commented on Jul 14, 2020

    @prashantkalkar

    @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.

  13. antonsmelyanskiy commented on Jul 21, 2020

    @antonsmelyanskiy

    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.

  14. scarby commented on Sep 4, 2020

    @scarby

    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)

  15. octplane commented on Oct 14, 2020

    @octplane

    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.

  16. github-actions commented on Jan 13, 2021

    @github-actions

    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.

  17. abryant-hv commented on Mar 18, 2021

    @abryant-hv

    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.

  18. ashtonian commented on Nov 16, 2021

    @ashtonian

    can't tell if this can be done or if stale-bot closed this?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stalev3.x

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions