Regular Cleanup of TaskRun and PipelineRun Resources
TOC
Overview
Automatically clean up TaskRun and PipelineRun resources in Tekton using the Pruner feature. The Pruner operates in the background by executing the tkn command to perform resource cleanup.
Use Cases
- Regularly clean up TaskRun resources
- Regularly clean up PipelineRun resources
- Configure different cleanup strategies based on namespaces
Prerequisites
- Tekton Operator component must be installed
- TektonConfig resource must have been automatically created in the environment
Steps
Step 1
Edit the TektonConfig resource
Step 2
Modify the spec.pruner configuration, as shown below:
Key configuration descriptions:
disabled: When set totrue, disables the pruner functionality (default value:false)schedule: Execution schedule for the cleanup task, using cron expression formatstartingDeadlineSeconds: Optional configuration for the deadline for task start (in seconds). If the task misses the scheduled time and exceeds this duration, it is counted as failedresources: Supported resource types for cleanup, includingtaskrunandpipelinerunkeep: Maximum number of resources to retain during cleanupkeep-since: Retain resources within a specified time (in minutes)prune-per-resource: When set totrue(default value isfalse), applies thekeepconfiguration separately for each resource- For example: If there are two Pipelines in namespace
ns-1, namedpipeline-1andpipeline-2, the following will be executed: - Note: When using
keep-since, enablingprune-per-resource=truehas no practical meaning, askeep-sinceis based on time constraint for resources, unrelated to the quantity of resources.
- For example: If there are two Pipelines in namespace
If disabled: false and schedule is empty, the global pruner task will be disabled.
However, if there is an annotation operator.tekton.dev/prune.schedule with a value in the namespace, a pruner task for that namespace will be created.
Step 3
Configure cleanup strategies via namespace annotations (optional)
By default, the pruner task will use the global configuration (spec.pruner), but users can customize the pruner configuration for specific namespaces through the following annotations. If certain annotations are missing or have invalid values, global configuration values will be used, or the namespace will be skipped.
Supported annotations:
operator.tekton.dev/prune.skip: When set totrue, skips the pruner task for that namespaceoperator.tekton.dev/prune.schedule: Sets the cleanup schedule for that namespaceoperator.tekton.dev/prune.keep: Sets the maximum number of resources to retainoperator.tekton.dev/prune.keep-since: Sets the retention period for resources within a specified time (in minutes)operator.tekton.dev/prune.prune-per-resource: Sets whether to apply the cleanup strategy separately for each resourceoperator.tekton.dev/prune.resources: Sets the types of resources to clean up, which can betaskrunand/orpipelinerun, with multiple values separated by commasoperator.tekton.dev/prune.strategy: Sets the cleanup strategy, with optional values ofkeeporkeep-since
Example:
::: note If no global configuration is set, the following default values will be used:
resources: pipelinerunkeep: 100:::
Results
After configuration is complete, the system will automatically clean up expired TaskRun and PipelineRun resources according to the set schedule.