3.13. Automatic pruning of task runs and pipeline runs
Stale TaskRun and PipelineRun objects and their executed instances occupy physical resources that can be used for active runs. For optimal utilization of these resources, Red Hat OpenShift Pipelines provides a pruner component that automatically removes unused objects and their instances in various namespaces.
You can configure the pruner for your entire installation by using the TektonConfig custom resource and modify configuration for a namespace by using namespace annotations. However, you cannot selectively auto-prune an individual task run or pipeline run in a namespace.
3.13.1. Configuring the pruner 复制链接链接已复制到粘贴板!
You can use the TektonConfig custom resource to configure periodic pruning of resources associated with pipeline runs and task runs.
The following example corresponds to the default configuration:
Example of the pruner configuration
apiVersion: operator.tekton.dev/v1alpha1
kind: TektonConfig
metadata:
name: config
# ...
spec:
pruner:
resources:
- taskrun
- pipelinerun
keep: 100
prune-per-resource: false
schedule: "* 8 * * *"
startingDeadlineSeconds: 60
# ...
| Parameter | Description |
|---|---|
|
| The Cron schedule for running the pruner process. The default schedule runs the process at 08:00 every day. For more information about the Cron schedule syntax, see Cron schedule syntax in the Kubernetes documentation. |
|
|
The resource types to which the pruner applies. The available resource types are |
|
| The number of most recent resources of every type to keep. |
|
|
If set to
If set to |
|
|
The maximum time for which to keep resources, in minutes. For example, to retain resources which were created not more than five days ago, set |
|
| This parameter is optional. If the pruner job is not started at the scheduled time for any reason, this setting configures the maximum time, in seconds, in which the job can still be started. If the job is not started within the specified time, OpenShift Pipelines considers this job failed and starts the pruner at the next scheduled time. If you do not specify this parameter and the pruner job does not start at the scheduled time, OpenShift Pipelines attempts to start the job at any later time possible. |
The keep and keep-since parameters are mutually exclusive. Use only one of them in your configuration.
To modify the configuration for automatic pruning of task runs and pipeline runs in a namespace, you can set annotations in the namespace.
The following namespace annotations have the same meanings as the corresponding keys in the TektonConfig custom resource:
-
operator.tekton.dev/prune.schedule -
operator.tekton.dev/prune.resources -
operator.tekton.dev/prune.keep -
operator.tekton.dev/prune.prune-per-resource -
operator.tekton.dev/prune.keep-since
The operator.tekton.dev/prune.resources annotation accepts a comma-separated list. To prune both task runs and pipeline runs, set this annotation to "taskrun, pipelinerun".
The following additional namespace annotations are available:
-
operator.tekton.dev/prune.skip: When set totrue, the namespace for which the annotation is configured is not pruned. -
operator.tekton.dev/prune.strategy: Set the value of this annotation to eitherkeeporkeep-since.
For example, the following annotations retain all task runs and pipeline runs created in the last five days and delete the older resources:
Example of auto-pruning annotations
kind: Namespace
apiVersion: v1
# ...
metadata:
annotations:
operator.tekton.dev/prune.resources: "taskrun, pipelinerun"
operator.tekton.dev/prune.keep-since: 7200
# ...
3.13.3. Enabling the event-based pruner 复制链接链接已复制到粘贴板!
The event-based pruner is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see Technology Preview Features Support Scope.
You can use the event-based tektonpruner controller to automatically delete completed resources, such as PipelineRuns and TaskRuns, based on configurable policies. Unlike the default job-based pruner, the event-based pruner listens for resource events and prunes resources in near real time.
You can use the event-based pruner together with the following:
Resource annotations Tekton Results Pipelines as Code
The Operator does not restrict the use of these features with the event-based pruner. However, future releases might introduce validation if conflicts are detected.
You must disable the default pruner in the TektonConfig custom resource (CR) before enabling the event-based pruner. If both pruner types are enabled, the deployment readiness status changes to False and the following error message is displayed in the output:
Components not in ready state: Invalid Pruner Configuration!! Both pruners, tektonpruner(event based) and pruner(job based) cannot be enabled simultaneously. Please disable one of them.
Procedure
In your TektonConfig CR, disable the default pruner by setting the
spec.pruner.disabledfield totrueand enable the event-based pruner by setting thespec.tektonpruner.disabledfield tofalse.apiVersion: operator.tekton.dev/v1alpha1 kind: TektonConfig metadata: name: config spec: # ... pruner: disabled: true # ... tektonpruner: disabled: false options: {} # ...After you apply the updated CR, the Operator deploys the
tekton-pruner-controllerpod in theopenshift-pipelinesnamespace.Verify that the following config maps are displayed in the
openshift-pipelinesnamespace:Expand ConfigMap Purpose tekton-pruner-default-specDefine default pruning behavior
pruner-infoStore internal runtime data used by the controller
config-logging-tekton-prunerConfigure logging settings for the pruner
config-observability-tekton-prunerEnable observability features such as metrics and tracing
Unlike the default pruner, you can only enable or disable the event-based pruner by modifying the TektonConfig CR. Configure all other pruning behavior by modifying the tekton-pruner-default-spec config map.
Verification
To verify that the
tekton-pruner-controllerpod is running, run the following command:$ oc get pods -n openshift-pipelinesVerify that the output includes a
tekton-pruner-controllerpod in theRunningstate. Example output:$ tekton-pruner-controller-<id> Running
3.13.4. Configuration of the event-based pruner 复制链接链接已复制到粘贴板!
The event-based pruner is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see Technology Preview Features Support Scope.
You can configure the pruning behavior for the event-based pruner by modifying the tekton-pruner-default-spec config map in the openshift-pipelines namespace. This config map supports both global pruning policies and optional namespace-specific overrides.
The following example shows a default tekton-pruner-default-spec config map that uses global pruning rules:
apiVersion: v1
kind: ConfigMap
metadata:
name: tekton-pruner-default-spec
namespace: openshift-pipelines
data:
global-config: |
enforcedConfigLevel: global
ttlSecondsAfterFinished: 300
successfulHistoryLimit: 3
failedHistoryLimit: 3
historyLimit: 5
# ...
-
ttlSecondsAfterFinished: 300: Delete resources 300 seconds (5 minutes) after completion. -
successfulHistoryLimit: 3: Retain 3 successful runs. -
failedHistoryLimit: 3: Retain 3 failed runs. -
historyLimit: 5: Limit retention to 5 runs. This setting is used if status-specific limits are not defined.
You can define pruning rules for individual namespaces by setting enforcedConfigLevel to namespace and configuring policies under the namespaces section. In the following example, a 60 second time to live (TTL) is applied to resources in the dev-project namespace:
# ...
data:
global-config: |
enforcedConfigLevel: namespace
ttlSecondsAfterFinished: 300
namespaces:
dev-project:
ttlSecondsAfterFinished: 60
# ...
You can use the following parameters in the global-config section of the tekton-pruner-default-spec config map:
| Parameter | Description |
|---|---|
|
| Delete resources after a fixed number of seconds following completion. |
|
| Retain the specified number of most recent successful runs, and delete older successful runs. |
|
| Retain the specified number of most recent failed runs, and delete older failed runs. |
|
| Apply a generic history limit when status-specific limits are not defined. |
|
|
Specify the level at which the pruner applies the configuration. Accepted values: |
|
| Define per-namespace pruning rules. |