FEAT(tekton): add automatic cleanup for old PipelineRuns
- Add CronJob to delete completed PipelineRuns older than 1 hour - Add 30m timeout to TriggerTemplates - Prevent resource accumulation in tekton-pipelines namespace
This commit is contained in:
36
tekton/ci-cd/manifests/cleanup-cronjob.yaml
Normal file
36
tekton/ci-cd/manifests/cleanup-cronjob.yaml
Normal file
@@ -0,0 +1,36 @@
|
||||
apiVersion: batch/v1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: tekton-cleanup
|
||||
namespace: tekton-pipelines
|
||||
spec:
|
||||
schedule: "0 * * * *" # Every hour
|
||||
successfulJobsHistoryLimit: 1
|
||||
failedJobsHistoryLimit: 1
|
||||
jobTemplate:
|
||||
spec:
|
||||
ttlSecondsAfterFinished: 300
|
||||
template:
|
||||
spec:
|
||||
serviceAccountName: tekton-triggers-sa
|
||||
containers:
|
||||
- name: cleanup
|
||||
image: bitnami/kubectl:latest
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- |
|
||||
echo "Cleaning up completed PipelineRuns older than 1 hour..."
|
||||
kubectl get pipelineruns -n tekton-pipelines \
|
||||
-o jsonpath='{range .items[?(@.status.conditions[0].status=="True")]}{.metadata.name}{" "}{.metadata.creationTimestamp}{"\n"}{end}' | \
|
||||
while read name timestamp; do
|
||||
if [ -n "$name" ]; then
|
||||
age=$(( ($(date +%s) - $(date -d "$timestamp" +%s 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%SZ" "$timestamp" +%s)) / 60 ))
|
||||
if [ "$age" -gt 60 ]; then
|
||||
echo "Deleting PipelineRun: $name (age: ${age}m)"
|
||||
kubectl delete pipelinerun "$name" -n tekton-pipelines
|
||||
fi
|
||||
fi
|
||||
done
|
||||
echo "Cleanup complete"
|
||||
restartPolicy: OnFailure
|
||||
Reference in New Issue
Block a user