<p>My aspired tekton usecase is simple:</p>
<ul>
<li>successful pipelineruns should be removed after x days</li>
<li>failed pipelineruns shouldn't be removed automatically.</li>
</ul>
<p>I plan to do the cleanup in an initial cleanup-task. That seems better to me than annotation- or cronjob-approaches. As long as nothing new is built, nothing has to be deleted.</p>
<p>Direct approaches:</p>
<ul>
<li><strong>Failed</strong>: <code>tkn delete</code> doesn't seem very helpful because it doesn't discriminate between successful or not.</li>
<li><strong>Failed</strong>: <code>oc delete --field-selector ...</code> doesn't contain the well hidden but highly expressive field <code>status.conditions[0].type==Succeeded</code></li>
</ul>
<p>Indirect approaches (first filtering a list of podnames and then delete them - not elegant at all):</p>
<ul>
<li><strong>Failed</strong>: Filtering output with <code>-o=jsonpath...</code> seems costly and the condition-array seems to break the statement, so that (why ever?!) everything is returned... not viable</li>
<li>My last attempt is <code>tkn pipelineruns list --show-managed-fields</code> and parse this with sed/awk... which is gross... but at least it does what I want it to do... and quite efficiently at that. But it might result as brittle when the design of the output is going to change in future releases...</li>
</ul>
<p>Do you have any better more elegant approaches?
Thanks a lot!</p>

staeppvargen
<p>Until a better solution is there, I'll post my current solution (and its drawbacks):</p>
<p>Our cleanup-task is now built around the following solution, evaluating the table returned by <code>tkn pipelineruns list</code>:</p>
<pre><code>tkn pipelineruns list --show-managed-fields -n e-dodo-tmgr --label tekton.dev/pipeline=deploy-pipeline | awk '$6~/Succeeded/ &amp;&amp; $3~/day|week|month/ {print $1}'
</code></pre>
<p>Advantages:</p>
<ul>
<li>It does what it should without extensive calls or additional calculation.</li>
</ul>
<p>Disadvantages:</p>
<ul>
<li>Time is limited to &quot;older than an hour / a day / a week ...&quot; But that's acceptable, since only successful builds are concerned.</li>
<li>I guess the design is quite brittle, because with changes in the tkn-Client the format of the table might change which implies that awk will pick the wrong columns, or similar pattern-probs.</li>
</ul>
<p>All in all I hope the solution will hold until there are some more helpful client-features that make the desired info directly filterable. Actually I'd hope for something like <code>tkn pipelineruns delete --state successful --period P1D</code>.
The notation for the time period is from ISO8601.</p>
