Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created October 14, 2020 13:04
Show Gist options
  • Save chmouel/89c6be1de507baec620c2a1c7c331848 to your computer and use it in GitHub Desktop.
Save chmouel/89c6be1de507baec620c2a1c7c331848 to your computer and use it in GitHub Desktop.
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: tkn-cleanup
spec:
failedJobsHistoryLimit: 1
successfulJobsHistoryLimit: 1
concurrencyPolicy: Replace
schedule: "0 0 * * *"
jobTemplate:
spec:
template:
spec:
serviceAccountName: tkn-aac-sa
containers:
- name: cleanup
image: docker.io/alpine/k8s:1.18.2
command: ["/bin/bash", "-c", "for ns in $(kubectl get pipelineruns -l tekton.dev/pipeline=tekton-as-a-code -o json | python3 -c \"import sys, datetime, json;jeez=json.load(sys.stdin);res=[ i['metadata']['name'] for i in jeez['items'] if datetime.datetime.now() > datetime.datetime.strptime(i['metadata']['creationTimestamp'], '%Y-%m-%dT%H:%M:%SZ') + datetime.timedelta(days=3) ];print(' '.join(res))\");do kubectl delete pipelinerun ${ns};done"]
restartPolicy: Never
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment