devspace-sh / devspace

DevSpace - The Fastest Developer Tool for Kubernetes ⚡ Automate your deployment workflow with DevSpace and develop software directly inside Kubernetes.
https://devspace.sh
Apache License 2.0
4.29k stars 359 forks source link

Unable to purge helm releases with dynamic releaseName in some cases #2525

Closed erikkrieg closed 1 year ago

erikkrieg commented 1 year ago

What happened? We have a devpsace configuration for a project that deploys different versions into the same namespace. With v6 we can use releaseName to deploy these different versions, but when we attempt to clean them up with devspace purge the wrong one can be uninstalled and the older ones enter a state where devspace purge will not remove them. It seems like when there are multiple versions deployed, the most recently deployed one is what gets purged and then the rest have to be dealt with manually.

What did you expect to happen instead? Given I have two deployed versions:

VERSION="foo" devspace deploy
VERSION="bar" devspace deploy

I would expect to purge version foo by running the following:

VERSION="foo" devspace purge

And in the case that I have removed version bar first, then I would expect to be able to purge foo with a subsequent run of the purge command.

How can we reproduce the bug? (as minimally and precisely as possible) Deploy the same project in the same namespace twice, and make sure the project deploys a helm release. The deployments should use a different releaseName so that there are two helm releases active in the namespace.

Then, use devpsace purge. You can attempt to "target" the older helm release by using the same releaseName that you created it with, or you can run it without any vars. Either way, you should see the the release that was created second was purged.

Try to run devpsace purge again and notice that no helm releases are uninstalled even though the first one is still installed.

My devspace.yaml:

Previously, in v5, we used a variable in the deployment name to prevent conflicts between these versions. Something like this:

deployments:
- name: example-app-${VERSION}

On v6, we are doing:

deployments:
  example-app:
    helm:
      releaseName: example-app-${VERSION}

Local Environment:

Anything else we need to know?

89luca89 commented 1 year ago

Thanks @erikkrieg for the report, we will take a look at it :+1:

89luca89 commented 1 year ago

Hey @erikkrieg taking a look on how you're using now v6, I think the best solution would be to use pipelines to achieve exactly the same behaviour you were expecting.

If you check this example:

version: v2beta1
name: myappname

pipelines:
  deploy:
    create_deployments my-app-${VERSION} --from example-app
  purge:
    purge_deployments my-app-${VERSION}

deployments:
  example-app:
    helm:
      chart:
        name: component-chart
        repo: https://charts.devspace.sh
      values:
        containers:
          - image: nginx:latest
        service:
          ports:
          - port: 3000

This will indeed work as you were expecting, you can use:

VERSION="foo" devspace deploy
VERSION="bar" devspace deploy

and then:

VERSION="foo" devspace purge
VERSION="bar" devspace purge

Tested and it works as you'd expect, let me know if this resolves your problems :smile:

erikkrieg commented 1 year ago

Oh, interesting. I didn't realize you could do that with create_deployments. I believe that this is a workable solution for me, thanks!