How can I command Helm NOT to throw an error if a release has nothing to release?

4/20/2020

I have a helm chart deploying to three environments (dev, stage and prod). My is running this command like this:

helm upgrade --install --namespace=$DEPLOYMENT_ENV ingress-external-api -f ./ingress-external-api/values-$DEPLOYMENT_ENV.yaml ./ingress-external-api --atomic

Where $DEVELOPMENT_ENV is either dev, stage or prod.

The important fact here is that only values-prod.yaml has a proper yaml definition. All the others values-dev.yaml and the same for stage are empty and therefore will not deploy any releases.

That results in the following helm error:

+ helm upgrade --install --namespace=$DEPLOYMENT_ENV ingress-external-api -f ./ingress-external-api/values-$DEPLOYMENT_ENV.yaml ./ingress-external-api --atomic
Release "ingress-external-api" does not exist. Installing it now.
INSTALL FAILED
PURGING CHART
Error: release ingress-external-api failed: no objects visited
Successfully purged a chart!
Error: release ingress-external-api failed: no objects visited

Which furthermore results in my bitbucket pipeline to stop and fail.

However as you also can see that did not help.

So my question is how can I tell helm not to throw an error at all if it can not find anything to substitute it's template with?

-- xetra11
bitbucket-pipelines
kubernetes-helm

3 Answers

4/21/2020

If you really don't want to deploy anything you can use empty values.yaml files and then add ifs and loops to your template files. Basically, you have to fill the values.yaml with an empty structure, e.g.:

my-release:
    value:
    other-value:

Then you can do something like:

{{ if .Values.my-release.value }}
-- Ronny
Source: StackOverflow

4/25/2020

how can I tell helm not to throw an error at all?

Add " || true" to the end of your command, something like this:

helm upgrade --install --namespace=$DEPLOYMENT_ENV ... || true

How it works

Most of the commands in the bitbucket-pipelines.yml file are bash/shell commands running on Unix. The program that runs the yml script will look for error exit codes from each command, to see whether the command has failed (to stop the script), or succeeded (to move onto the next command).

When you add "|| true" to the end of a shell command, it means "ignore any errors, and return success code 0 always". Here's a demonstration, which you can run in a Terminal window on your local computer:

echo "hello" # Runs successfully
echo $? # Check the status code of the last command. It should be 0 (success)

echo-xx "hello" # Runs with error, becuase there is no command called "echo-xx"
echo $? # Check the status code of the last command. It should be 127 (error)

echo-xx "hello" || true # Runs with success, even though "echo-xx" ran with an error
echo $? # Check the status code of the last command. It should be 0 (success)

More Info about shell return codes:

-- Mr-IDE
Source: StackOverflow

4/20/2020

I am not sure this is supposed to be helm's responsibility. Why do you want to update dev/stage with missing values ? It seems a little bit weird.

If you are not going to update anything there, just run it once in production only.

If you insist doing it that way, there's also the possibility to 'lie' about your returning code in Bash and implement it on pipeline level.

Lie about exit status

-- Recoba20
Source: StackOverflow