<p>How can I delete release older than, for example, the 1st of October?
I mean updated before the 1st of October.<br>
Alternatively, delete all releases with the app version lower than _.</p>

<p>Helm ls output: </p>

<blockquote>
  <p>|NAME|REVISION|UPDATED                 |STATUS  |CHART   |APP VERSION|NAMESPACE|<br>
  |myapp| 8     |Fri Sep 27 17:27:20 2019|DEPLOYED|myapp.85|85         |default|</p>
</blockquote>

<p>The following command deletes just one.</p>

<blockquote>
  <p>helm delete relase_name</p>
</blockquote>

<p>The following is not a great solution as well </p>

<blockquote>
  <p>helm delete relase_name1 relase_name2 relase_name3</p>
</blockquote>

<p><strong>Note1:</strong> I don't want to delete all. There is an explanation of how to do that over here <a href="https://stackoverflow.com/questions/47817818/helm-delete-all-releases">Helm delete all releases</a> and I don't want to do that. However, I assume I need to use bash for this task.</p>

<p><strong>Note2:</strong> I have already read documentation it is not that big. There is nothing over there about filtering.
<a href="https://helm.sh/docs/helm/#helm-delete" rel="noreferrer">https://helm.sh/docs/helm/#helm-delete</a></p>

<p><strong>Note3:</strong> I have already looked into helm sources, I am not 100% sure but It doesn't look like it is possible <a href="https://github.com/helm/helm/tree/master/pkg/helm" rel="noreferrer">https://github.com/helm/helm/tree/master/pkg/helm</a></p>

<p>Thank you in advance!</p>

Sergii Zhuravskyi
<p><em>Assuming Helm version 3+</em></p>

<p>You can use <code>jq</code> and <code>xargs</code> to accomplish this:</p>

<p><strong>Question 1</strong>, to delete releases that were last updated before <code>$TIMESTAMP</code> (in seconds):</p>

<pre><code>helm ls -o json | jq -r --argjson timestamp $TIMESTAMP '.[] | select (.updated | sub("\\..*";"Z") | sub("\\s";"T") | fromdate &lt; now - $timestamp).name' | xargs -L1 helm uninstall
</code></pre>

<blockquote>
  <p><code>sub("\\..*";"Z") | sub("\\s";"T")</code> converts the date format
  Helm uses in their output to ISO 8601.</p>
</blockquote>

<p><strong>Question 2</strong>, to delete releases with an app version older than <code>$VERSION</code>:</p>

<pre><code>helm ls -o json | jq -r --argjson version $VERSION '.[] | select(.app_version | sub("\\.[0-9]$";"") | tonumber | . &lt; $version).name' | xargs -L1 helm uninstall
</code></pre>

<blockquote>
  <p><code>$VERSION</code> should be major or major.minor only (i.e. <code>2</code> or
  <code>2.1</code>). don't use a patch number.</p>
</blockquote>

<p><strong>Question 3</strong>, to delete releases by their initial deploy date, you'll have to parse the contents of the <code>helm history RELEASE</code> command for each release.</p>

<p>I won't solve this one, but it would look something like:</p>

<pre><code>loop over helm ls
  get release name
  get first entry of helm history for that release
  pass to jq and process like the answer for question 1
</code></pre>

<p>Relevant Links:</p>

<ul>
<li><a href="https://stedolan.github.io/jq/manual/#select(boolean_expression)" rel="noreferrer">https://stedolan.github.io/jq/manual/#select(boolean_expression)</a></li>
<li><a href="https://stedolan.github.io/jq/manual/#sub(regex;tostring)sub(regex;string;flags)" rel="noreferrer">https://stedolan.github.io/jq/manual/#sub(regex;tostring)sub(regex;string;flags)</a></li>
<li><a href="https://stedolan.github.io/jq/manual/#Dates" rel="noreferrer">https://stedolan.github.io/jq/manual/#Dates</a></li>
<li><a href="https://helm.sh/docs/helm/helm_history/" rel="noreferrer">https://helm.sh/docs/helm/helm_history/</a></li>
</ul>
