Last active
February 23, 2023 20:27
-
-
Save chmouel/a77e81db853ce3b58be4700dd1884dde to your computer and use it in GitHub Desktop.
cronjob for pruning pipelinerun objects by age
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: List | |
items: | |
- apiVersion: batch/v1beta1 | |
kind: CronJob | |
metadata: | |
name: pr-cleanup | |
namespace: ghe | |
spec: | |
concurrencyPolicy: Replace | |
failedJobsHistoryLimit: 1 | |
jobTemplate: | |
metadata: | |
creationTimestamp: null | |
spec: | |
template: | |
metadata: | |
creationTimestamp: null | |
spec: | |
containers: | |
- command: | |
- /bin/bash | |
- -c | |
- for pr in $(kubectl get pipelineruns | |
-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=1) ];print(' '.join(res))");do kubectl delete | |
pipelinerun ${ns};done | |
image: public.ecr.aws/bitnami/kubectl:latest | |
imagePullPolicy: IfNotPresent | |
name: cleanup | |
terminationMessagePath: /dev/termination-log | |
terminationMessagePolicy: File | |
dnsPolicy: ClusterFirst | |
restartPolicy: Never | |
schedulerName: default-scheduler | |
serviceAccount: pipelines-as-code-sa-el | |
serviceAccountName: pipelines-as-code-sa-el | |
terminationGracePeriodSeconds: 30 | |
schedule: 0 0 * * * | |
successfulJobsHistoryLimit: 1 | |
suspend: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment