Files
platform/tekton/ci-cd/manifests/cleanup-cronjob.yaml
Mayne0213 90f204a0f5 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
2026-01-11 01:41:21 +09:00

37 lines
1.3 KiB
YAML

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