|
| 1 | +--- |
| 2 | +status: proposed |
| 3 | +title: Optional Flag for Enabling PVCs Auto Removal Behavior |
| 4 | +creation-date: '2025-05-26' |
| 5 | +last-updated: '2025-05-26' |
| 6 | +authors: |
| 7 | +- '@fambelic' |
| 8 | +collaborators: [] |
| 9 | +--- |
| 10 | + |
| 11 | +# TEP-0161: Add an optional flag for enabling PVCs Auto Removal behavior when coschedule is set to `workspaces` |
| 12 | + |
| 13 | +- [Summary](#summary) |
| 14 | +- [Motivation](#motivation) |
| 15 | + - [Goals](#goals) |
| 16 | + - [Non-Goals](#non-goals) |
| 17 | +- [Proposal](#proposal) |
| 18 | +- [Design Details](#design-details) |
| 19 | +- [Design Evaluation](#design-evaluation) |
| 20 | + - [Reusability](#reusability) |
| 21 | + - [Drawbacks](#drawbacks) |
| 22 | +- [Implementation Plan](#implementation-plan) |
| 23 | + - [Test Plan](#test-plan) |
| 24 | +- [References](#references) |
| 25 | + |
| 26 | + |
| 27 | +## Summary |
| 28 | +This is a very small TEP aimed at extending existing functionality. The general concept has already been discussed in prior resources: |
| 29 | +- [TEP-0135: Coscheduling PipelineRun Pods](https://github.com/tektoncd/community/blob/main/teps/0135-coscheduling-pipelinerun-pods.md) |
| 30 | +- [Discussion](https://github.com/tektoncd/pipeline/pull/6741#issuecomment-1610123340) |
| 31 | + |
| 32 | +In [PR #6940](https://github.com/tektoncd/pipeline/pull/6940), two new feature flags (`pipelineruns` and `isolated-pipelineruns`) related to the `AffinityAssistant` were added to modify node scheduling behavior and enable automatic deletion of workspace `PVCs` when PipelineRuns complete. |
| 33 | +This TEP proposes adding the same PVC auto-removal behavior through an optional flag when `coschedule` mode is set to `workspaces`. |
| 34 | +This maintains backward compatibility while providing users with the option to enable automated cleanup of PVCs associated with PipelineRuns in workspaces mode. |
| 35 | +## Motivation |
| 36 | +Automatic PVC removal can help reduce cluster storage consumption and improve resource management. |
| 37 | +By enabling this behavior in `workspaces` coschedule mode, users can benefit from auto-cleanup even when pods are scheduled based on shared workspaces. Letting the controller handle PVC cleanup upon PipelineRun completion reduces storage waste and improves the user experience when inspecting Kubernetes objects, as it avoids cluttering the namespace with useless PVCs. |
| 38 | + |
| 39 | +### Goals |
| 40 | +- Allow users to enable PVC auto-removal when using `workspaces` coschedule mode. |
| 41 | +### Non-Goals |
| 42 | +- Unless explicitly overridden, it does not alter the default behavior of `workspaces` coschedule mode, where PVCs are retained after PipelineRun completion. |
| 43 | +- It does not change how PVCs are created or the ownership model, where PipelineRuns are the owners of PVCs created via the `Affinity Assistant`. |
| 44 | +## Proposal |
| 45 | +This TEP proposes a new optional boolean flag called `enable-pvc-auto-removal` within feature-flags ConfigMap that can be set to true when the auto-removal behavior wants to be enabled when the coschedule mode is set to `workspaces`. |
| 46 | +Here's an example of the proposed feature: |
| 47 | +```yaml |
| 48 | +apiVersion: v1 |
| 49 | +kind: ConfigMap |
| 50 | +metadata: |
| 51 | + name: feature-flags |
| 52 | + namespace: tekton-pipelines |
| 53 | + labels: |
| 54 | + app.kubernetes.io/instance: default |
| 55 | + app.kubernetes.io/part-of: tekton-pipelines |
| 56 | +data: |
| 57 | + coschedule: "workspaces" |
| 58 | + enable-pvc-auto-removal: "true" |
| 59 | + ..... |
| 60 | +``` |
| 61 | +This flag is only evaluated when coschedule is set to `workspaces`. If set to "`true`, the controller removes PVCs associated with completed PipelineRuns. If omitted or set to `false`, the default behavior is preserved and PVCs remain. |
| 62 | +## Design Details |
| 63 | + |
| 64 | +The new flag is a boolean with the following behavior: |
| 65 | + - `true`: PVCs are automatically deleted once their associated PipelineRuns complete, using the same logic already implemented for other coschedule modes. |
| 66 | + - `false`(default): PVCs persist alongside completed PipelineRuns. |
| 67 | +### Reusability |
| 68 | +The proposed change would reuse the PVC cleanup logic already in place for the other modes. This minimizes implementation effort and ensures consistency across modes. |
| 69 | +### Drawbacks |
| 70 | +- While it does not cause functional issues, enabling this flag introduces a small inconsistency: PVCs are still owned by PipelineRuns, but are deleted automatically. |
| 71 | +## Implementation Plan |
| 72 | + |
| 73 | +1. Add the `enable-pvc-auto-removal` flag to the `FeatureFlags` struct. |
| 74 | +2. Modify the Affinity Assistant logic to check on the new flag in `workspaces` mode. |
| 75 | +3. Ensure backward compatibility by defaulting the flag to false. |
| 76 | + |
| 77 | +### Test Plan |
| 78 | + |
| 79 | +- Add unit tests for the new flag behavior. |
| 80 | +- If necessary, add integration and/or e2e tests verifying PVC removal in workspaces mode when the flag is enabled. |
| 81 | + |
| 82 | +## References |
| 83 | +- [TEP](https://github.com/tektoncd/community/blob/main/teps/0135-coscheduling-pipelinerun-pods.md) |
| 84 | +- [Discussion](https://github.com/tektoncd/pipeline/pull/6741#issuecomment-1610123340) |
| 85 | +- [Commit](https://github.com/tektoncd/pipeline/commit/84b8621df194177fe26f53d8b330387295517484) |
0 commit comments