Can I run a Helm command on all releases of a given chart?

7/23/2018

I'm frequently installing multiple instances of an umbrella Helm chart across multiple namespaces for testing. I'd like to continue using the randomly generated names, but also be able to tear down multiple releases of the same chart in one command that doesn't need to change for each new release name.

So for charts like this:

$ helm ls
NAME                REVISION    UPDATED                     STATUS      CHART                 NAMESPACE
braided-chimp       1           Mon Jul 23 15:52:43 2018    DEPLOYED    foo-platform-0.2.1    foo-2
juiced-meerkat      1           Mon Jul  9 15:19:43 2018    DEPLOYED    postgresql-0.9.4      default
sweet-sabertooth    1           Mon Jul 23 15:52:34 2018    DEPLOYED    foo-platform-0.2.1    foo-1

I can delete all releases of the foo-platform-0.2.1 chart by typing the release names like:

$ helm delete braided-chimp sweet-sabertooth

But every time I run the command, I have to update it with the new release names.

Is it possible to run list / delete on all instances of a given chart across all namespaces based on the chart name? (I'm thinking something like what kubectl supports with the -l flag.)

For instance, how can I achieve something equivalent to this?

$ helm delete -l 'chart=foo-platform-0.2.1'

Is there a better way to do this?

-- Taylor Edmiston
kubernetes
kubernetes-helm

2 Answers

9/3/2019

I wanted to see if I could achieve the same result using jq instead of awk.

I'm not an expert on jq so there might simpler methods. Test with a dry run!

Assuming Bash:

CHARTID=foo-platform-0.2.1
helm delete --dry-run $(helm ls --output json | jq -r ".Releases[] | select(.Chart == \"${CHARTID}\") | .Name")

with the above example I would expect the output to be:

release "braided-chimp" deleted
release "sweet-sabertooth" deleted
-- Mark McLaren
Source: StackOverflow

7/24/2018

You could try:

helm delete $(helm ls | awk '$9 ~ /SEARCH/ { print $1 }')

Replacing SEARCH with whatever chart name pattern you want to use

It gets thrown off a little because awk is going to delimit on the spaces, which the timestamp has several of.

So what would traditionally be tab delimited:

1=NAME 2=REVISION 3=UPDATED 4=STATUS 5=CHART 6=NAMESPACE

becomes:

1=mottled-whippet 2=1 3=Fri 4=Jul 5=20 6=13:15:45 7=2018 8=DEPLOYED 9=postgresql-0.15.0 10=namespace

-- cwurtz
Source: StackOverflow