Retention Policy Configuration
Tekton Results retention policy provides automated cleanup for both database records and archived logs in S3-compatible storage systems. The retention agent periodically removes expired results according to configurable time-based policies and deletes their associated log payloads on a best-effort basis (see Retention Value Limits).
TOC
ConfigurationConfiguration ParametersRetention Value LimitsRelationship with In-Cluster PruningPer-Namespace or Per-Label RetentionApply ConfigurationImportant NoteVerificationConfiguration
Retention policies are configured through the TektonConfig custom resource using the spec.result.options field to specify ConfigMap overrides:
Configuration Parameters
The defaults above are the values in the tekton-results-config-results-retention-policy ConfigMap installed with Tekton Results. If defaultRetention is removed from the ConfigMap, the retention agent falls back to a built-in value of 30 days instead of failing. There is no usable fallback for runAt: keep it set to a valid five-field cron expression. Its built-in value, 7 7 * * 7, is rejected by the cron parser the retention agent uses, which only accepts day-of-week values from 0 to 6, so the retention agent fails to start when runAt is removed or is not a valid cron expression.
defaultRetention accepts three equivalent formats: a plain integer is a number of days ("30"), a d suffix also means days ("30d"), and any other value is parsed as a Go duration ("720h").
-
defaultRetention: Specifies how long to retain results before automatic deletion. After this period elapses, the database records are deleted and the retention agent also tries to delete the associated log payloads in S3 storage; log deletion is best effort, see Retention Value Limits. -
runAt: Cron expression defining when the retention agent runs."0 2 * * *"- Daily at 2:00 AM"0 2 * * 0"- Weekly on Sundays at 2:00 AM"0 2 1 * *"- Monthly on the 1st at 2:00 AM
Retention Value Limits
- No upper bound or sign check:
defaultRetentionand each policyretentionvalue are only checked for a parsable format. Tekton Results does not cap the retention period; choose it according to your own audit or compliance requirements. A value in days (a plain integer or thedsuffix) is converted to a Gotime.Durationwithout an overflow check, so a value above 106751 days (about 292 years) wraps around to an unrelated duration, which can be negative or close to zero, and the next run then deletes results as described in the next item. Do not use a very large number to mean "keep forever". A Go duration string above the same limit, such as"2562048h", fails to parse instead. "0"and negative values delete every result they cover: A result expires when its record was last updated beforenow - retention. With"0"the cutoff is the time the job runs, and with a negative value the cutoff is in the future. The retention that applies to a result is the one of its first matching policy, ordefaultRetentionwhen no policy matches (see Per-Namespace or Per-Label Retention). So a policyretentionof"0"or less makes the next run delete every result whose first matching policy it is, and adefaultRetentionof"0"or less makes it delete every result that matches no policy. Their logs are deleted on a best-effort basis, as described in the next item.- Log deletion is best effort: Deleting log payloads from external storage can be turned off by a feature gate, and a deletion that still fails after its retries is ignored so that the database cleanup proceeds. Log payloads can therefore remain in storage after their result records are gone. If log expiry is a requirement, also configure a lifecycle rule on the storage bucket, or monitor the bucket for log payloads older than the retention period.
- A leftover
maxRetentionoverridesdefaultRetention: The deprecatedmaxRetentionkey is still read. When it is present, its value is used as the default retention anddefaultRetentionis ignored; the retention agent only logs a deprecation warning. Before you rely ondefaultRetention, removemaxRetentionfrom the ConfigMap, moving its value todefaultRetentionif you want to keep it.
Relationship with In-Cluster Pruning
The upstream Tekton Results documentation recommends using the retention policy together with an in-cluster pruning mechanism such as Tekton Pruner, with a Results retention period longer than the in-cluster retention period. This avoids a pruned result being re-created in the database while its PipelineRun or TaskRun still exists in the cluster.
Per-Namespace or Per-Label Retention
Use the policies key to give selected results their own retention period, for example a longer period for namespaces that hold audit-relevant pipelines. policies is a YAML string containing a list of policies, each with a name, a selector, and a retention value (same formats as defaultRetention):
- Policies are evaluated in order, and the first matching policy applies. Results that match no policy use
defaultRetention. - A
selectorcan combinematchNamespaces,matchLabels,matchAnnotations, andmatchStatuses. All specified fields must match; within one field, any listed value matches.matchLabelsandmatchAnnotationsmap a key to a list of accepted values and are evaluated against the PipelineRun or TaskRun metadata.matchStatusesis evaluated against thereasonof the first status condition, such asSucceededorFailed.
The following example keeps results from one namespace and from runs with one label for different periods. It shows only the retention keys: merge them into spec.result.options of the existing TektonConfig (for example with kubectl edit tektonconfig config) and keep its other spec.result fields, such as the database and log settings shown in Configuration:
Apply Configuration
Apply the TektonConfig configuration. The file must contain the complete spec.result you want, including the existing database and log settings; to change only the retention keys, edit the existing TektonConfig instead of applying a file that holds only those keys:
Example Output:
Wait for the retention agent to restart:
Example Output:
Verify the configuration is active:
Example Output:
Important Note
Important: The unified cleanup functionality (deleting database records and, on a best-effort basis, their S3 log payloads; see Retention Value Limits) is a enhancement (patch-based) and is not currently available in community Tekton Results. The community version only removes database records but leaves log payloads in S3 storage, which can lead to unbounded storage growth.
Check TektonConfig retention configuration:
Example Output (abbreviated):
Check retention agent logs:
Example Output:
Verification
To quickly verify that the retention policy is functioning as expected, follow these steps:
-
Create test results/logs: Generate some Tekton PipelineRuns or TaskRuns that will produce results and logs in your Tekton Results database.
-
Verify initial state: Check that the results and logs are present in the database and S3 storage (if applicable).
-
Modify retention policy for testing: Temporarily set a very short retention period and a specific cron schedule for testing purposes (e.g., execute once at current time + 10 minutes).
-
Apply modified configuration: Apply the temporary test configuration and wait for the retention agent to restart.
-
Monitor retention agent logs: Watch the retention agent logs to confirm cleanup operations are occurring.
-
Verify cleanup occurred: After the retention schedule executes, verify that the older results and logs have been removed.
-
Revert to production settings: Once verified, revert the retention policy to your intended production values.
Warning: Be careful when setting very short retention periods as this will delete results immediately. Ensure you are using a test environment for verification.