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

Quick fix: helm delete --purge the release and try again.

Question

Helm Upgrade Failed

"cloudposse-incubator" has been added to your repositories
exec: helm repo update --kube-context us-west-2-staging-example-com
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "cloudposse-incubator" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈
exec: helm upgrade --install pr-1627-app-pull-secret cloudposse-incubator/dockercfg --version 0.1.0 --namespace pr-1627-app --wait --timeout=600 --force --reset-values --kube
-context us-west-2-staging-example-com
Error: UPGRADE FAILED: failed to create resource: namespaces "pr-1627-app" not found
err: exit status 1
[SYSTEM] Error: Failed to run freestyle step: Deploy backing services with helmfile (for unlimited staging environments); caused by NonZeroExitCodeError: Container
for step title: Deploy backing services with helmfile (for unlimited staging environments), step type: freestyle, operation: Freestyle step failed with exit code: 1

Answer

This usually happens when the state of the resources (e.g. Deployments, Services, Namespaces, etc) in the kubernetes cluster does not match what Helm knows about. In the example above, the namespace had been deleted without first deleting the helm releases. So helm attempted to perform an upgrade on a non-existent resource.

To fix this, simply delete the errant helm release. In this case, we would run the following command to delete the pr-1627-app helm release.

helm delete --purge pr-1627-app

To avoid this, only use helm commands to operate on kubernetes resources.