Helm 3 does not seem to have a good way to “uninstall if exists” unfortunately. So, we had to find a way around that to make sure we could wipe out a previous deployment reliably, in CI/CD (in cases where we had to change a deployment version, which is rare).
As we use GitLab, we found this trick in the docs:
If any of the script commands return an exit code different from zero, the job will fail and further commands won’t be executed. This behavior can be avoided by storing the exit code in a variable:
job:
script:
- false || exit_code=$?
- if [ $exit_code -ne 0 ]; then echo "Previous command failed"; fi;
Using this, you can do:
helm uninstall -n your-namespace some-deployment-0-0-5 || exit_code=$?
And, while you’ll receive a note that it didn’t work on any release after it’s gone, the pipeline will continue on fine.