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:
2026-01-11 01:41:21 +09:00
parent 4a1a718060
commit 90f204a0f5
3 changed files with 42 additions and 0 deletions

View 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