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.
Edit the TektonConfig
resource
Modify the spec.pruner
configuration, as shown below:
Key configuration descriptions:
disabled
: When set to true
, 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, including taskrun
and pipelinerun
keep
: Maximum number of resources to retain during cleanupkeep-since
: Retain resources within a specified time (in minutes)prune-per-resource
: When set to true
(default value is false
), applies the keep
configuration separately for each resource
ns-1
, named pipeline-1
and pipeline-2
, the following will be executed:
keep-since
, enabling prune-per-resource=true
has no practical meaning, as keep-since
is based on time constraint for resources, unrelated to the quantity of resources.
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.
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 to true
, 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 be taskrun
and/or pipelinerun
, with multiple values separated by commasoperator.tekton.dev/prune.strategy
: Sets the cleanup strategy, with optional values of keep
or keep-since
Example:
::: note If no global configuration is set, the following default values will be used:
resources: pipelinerun
keep: 100
:::After configuration is complete, the system will automatically clean up expired TaskRun and PipelineRun resources according to the set schedule.