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
# ...

Expand
表 3.3. Supported parameters for pruner configuration
ParameterDescription

schedule

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.

resources

The resource types to which the pruner applies. The available resource types are taskrun and pipelinerun

keep

The number of most recent resources of every type to keep.

prune-per-resource

If set to false, the value for the keep parameter denotes the total number of task runs or pipeline runs. For example, if keep is set to 100, then the pruner keeps 100 most recent task runs and 100 most recent pipeline runs and removes all other resources.

If set to true, the value for the keep parameter is calculated separately for pipeline runs referencing each pipeline and for task runs referencing each task. For example, if keep is set to 100, then the pruner keeps 100 most recent pipeline runs for Pipeline1, 100 most recent pipeline runs for Pipeline2, 100 most recent task runs for Task1, and so on, and removes all other resources.

keep-since

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 keep-since to 7200.

startingDeadlineSeconds

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 to true, the namespace for which the annotation is configured is not pruned.
  • operator.tekton.dev/prune.strategy: Set the value of this annotation to either keep or keep-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

  1. In your TektonConfig CR, disable the default pruner by setting the spec.pruner.disabled field to true and enable the event-based pruner by setting the spec.tektonpruner.disabled field to false.

    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-controller pod in the openshift-pipelines namespace.

  2. Verify that the following config maps are displayed in the openshift-pipelines namespace:

    Expand
    ConfigMapPurpose

    tekton-pruner-default-spec

    Define default pruning behavior

    pruner-info

    Store internal runtime data used by the controller

    config-logging-tekton-pruner

    Configure logging settings for the pruner

    config-observability-tekton-pruner

    Enable 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

  1. To verify that the tekton-pruner-controller pod is running, run the following command:

    $ oc get pods -n openshift-pipelines
  2. Verify that the output includes a tekton-pruner-controller pod in the Running state. 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:

Expand
ParameterDescription

ttlSecondsAfterFinished

Delete resources after a fixed number of seconds following completion.

successfulHistoryLimit

Retain the specified number of most recent successful runs, and delete older successful runs.

failedHistoryLimit

Retain the specified number of most recent failed runs, and delete older failed runs.

historyLimit

Apply a generic history limit when status-specific limits are not defined.

enforcedConfigLevel

Specify the level at which the pruner applies the configuration. Accepted values: global or namespace.

namespaces

Define per-namespace pruning rules.

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部