Time-based Pruning (TTL)

Delete completed resources after a specified duration using ttlSecondsAfterFinished.

TOC

How It Works

TTL applies to all completed runs (successful and failed). The timer starts when the run finishes.

Basic Configuration

apiVersion: operator.tekton.dev/v1alpha1
kind: TektonConfig
metadata:
  name: config
spec:
  pruner:
    disabled: true  # Must disable job-based pruner
  tektonpruner:
    disabled: false  # Enable event-based pruner
    global-config:
      ttlSecondsAfterFinished: 3600  # Delete after 1 hour

Common TTL Values

DurationSecondsUse Case
5 minutes300Dev/test rapid iteration
1 hour3600CI pipelines
1 day86400General workloads
7 days604800Staging/release
30 days2592000Production/audit/compliance

Environment-specific TTLs

spec:
  tektonpruner:
    global-config:
      enforcedConfigLevel: namespace
      ttlSecondsAfterFinished: 3600  # Default
      namespaces:
        dev:
          ttlSecondsAfterFinished: 300      # 5 min
        staging:
          ttlSecondsAfterFinished: 86400    # 1 day
        prod:
          ttlSecondsAfterFinished: 2592000

Pipeline-specific TTLs

Use selectors in namespace ConfigMaps for pipeline-specific TTLs:

WARNING

Namespace-level ConfigMaps are outside the TektonConfig lifecycle. If you need to back up or restore Tekton configuration later, save these ConfigMaps separately.

apiVersion: v1
kind: ConfigMap
metadata:
  name: tekton-pruner-namespace-spec
  namespace: my-app
  labels:
    app.kubernetes.io/part-of: tekton-pruner
    pruner.tekton.dev/config-type: namespace
data:
  ns-config: |
    ttlSecondsAfterFinished: 3600
    pipelineRuns:
      - selector:
          matchLabels:
            pipeline-type: release
        ttlSecondsAfterFinished: 604800
      - selector:
          matchLabels:
            pipeline-type: test
        ttlSecondsAfterFinished: 300

Combining TTL with History Limits

History limits override TTL to guarantee minimum retention:

data:
  ns-config: |
    ttlSecondsAfterFinished: 300
    successfulHistoryLimit: 5
    failedHistoryLimit: 10

Result: Runs are deleted after 5 minutes UNLESS they're in the last 5 successful or last 10 failed.

Best Practices

  1. Development: Short TTLs (5-60 min) for rapid iteration
  2. Production: Long TTLs (7-30 days) for audit/compliance
  3. Critical Pipelines: Use selectors for extended retention
  4. Balance: Consider storage costs vs. retention needs