-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Proposal: Optional PVC Auto-Cleanup for Workspaces Mode
Problem
Users running PipelineRuns with volumeClaimTemplate in stable workspaces mode accumulate PVCs after completion, causing increased storage costs and manual cleanup burden. Alpha modes (pipelineruns, isolate-pipelinerun) auto-delete PVCs, but there's no stable/production-ready option.
Related: #5776 | Code: pkg/reconciler/pipelinerun/affinity_assistant.go:214 (TODO comment)
Proposed Solution
Add opt-in annotation tekton.dev/auto-cleanup-pvc: "true" to enable PVC cleanup on PipelineRun completion.
Example:
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: build-app
annotations:
tekton.dev/auto-cleanup-pvc: "true"
spec:
workspaces:
- name: source
volumeClaimTemplate:
spec:
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 1GiBehavior:
- With annotation: PVC deleted on completion
- Without annotation: Current behavior (PVC persists until PipelineRun deleted)
- Fully backward compatible
Implementation
Key insight: Cleanup logic already exists in PurgeFinalizerAndDeletePVCForWorkspace() (used by alpha modes). Just need to call it conditionally.
Changes in pkg/reconciler/pipelinerun/affinity_assistant.go:
// Add constant
const AutoCleanupPVCAnnotation = "tekton.dev/auto-cleanup-pvc"
// Modify cleanup (lines 213-222)
case aa.AffinityAssistantPerWorkspace:
for _, w := range pr.Spec.Workspaces {
// ... existing StatefulSet deletion ...
// NEW: Check annotation
autoCleanup := pr.Annotations != nil && pr.Annotations[AutoCleanupPVCAnnotation] == "true"
if w.VolumeClaimTemplate != nil && autoCleanup {
pvcName := volumeclaim.GeneratePVCNameFromWorkspaceBinding(...)
c.pvcHandler.PurgeFinalizerAndDeletePVCForWorkspace(ctx, pvcName, pr.Namespace)
}
}Complexity: ~20 lines code + ~150 lines tests + docs
Why Annotation?
- ✅ Backward compatible (opt-in)
- ✅ Per-PipelineRun control
- ✅ Reuses existing cleanup logic
- ✅ Standard Kubernetes pattern
Alternative (cluster-wide flag) could be added later if needed.
Questions
- Is
tekton.dev/auto-cleanup-pvcan acceptable annotation name? - Should this also work for
persistentVolumeClaimworkspaces, or onlyvolumeClaimTemplate? - Should we include a cluster-wide feature flag in this PR or defer?
References
- Allow PVC of completed PipelineRun to be deleted #5776
- Alpha implementation: TEP-0135: Refactor Affinity Assistant PVC creation #6741, [TEP-0135] Purge finalizer and delete PVC #6940
- TEP-0135: https://github.com/tektoncd/community/blob/main/teps/0135-coscheduling-pipelinerun-pods.md
Happy to implement if approach is approved.
cc @tektoncd/maintainers
Metadata
Metadata
Assignees
Labels
Type
Projects
Status