openshift, Tech Stuff, Tekton

Auto pruning of Openshift Tekton pipelines.

Tekton pipelines are cool. But what’s not cool are all the resources that are left hanging around from all the pipelineruns, that have executed. Need to tidy that up.

You could do it manually. This would mean that you literally have f all else to do with your day. Or.. you could use annotations to let Openshift pipelines clear up the mess, automatically.

Heres how to do it and what to look out for.

DON’T USE THE CONSOLE.

It doesn’t work. Well.. it kinda works, but then kinda of not, so in my book – that means it doesn’t. Stay away from it and use the oc command.

Edit the target namespace

You’re going to add the following annotations, in the annotations section (obvs)

    operator.tekton.dev/prune.keep-since: "60"
    operator.tekton.dev/prune.resources: taskrun,pipelinerun

You need to edit the namespace/project that you are running the pipelines in, and set the number of minutes to remove resources that are OLDER than this value. I set to 60 mins.

The next line determines which resources you want to remove – task runs and pipeline runs seem the most obvious to me – but if anyone has any examples of any other useful resources to remove – let me know.

I will use pipelines-testing namespace for this example.

Log in and run the following

$ oc edit namespace pipeline-testing 

Add the annotations as highlighted below in bold.

apiVersion: v1
kind: Namespace
metadata:
  annotations:
    openshift.io/description: ""
    openshift.io/display-name: ""
    openshift.io/requester: scott
    openshift.io/sa.scc.mcs: s0:c27,c19
    openshift.io/sa.scc.supplemental-groups: 1000740000/10000
    openshift.io/sa.scc.uid-range: 1000740000/10000
    operator.tekton.dev/prune.hash: 13962c29c3ca7981c17ed1ca562e231d37990a38ab15e738bff7a665433b8614
    operator.tekton.dev/prune.keep-since: "60"
    operator.tekton.dev/prune.resources: taskrun,pipelinerun

Save and exit. You’re done. You now have more time to spend on mastodon and no more worries about unused PVCs consuming your storage.

If this was helpful and you would like to buy me a coffee, it would be greatly appreciated!

Buy Me A Coffee

Leave a comment