Automatic Cleanup
kontinue can automatically clean up completed Executions using TTL (time-to-live) configuration. This prevents your cluster from accumulating old execution resources while optionally preserving execution history in a compact archived format.
Configuration
Configure TTL in the Execution spec:
apiVersion: kontinue.cloud/v1alpha1
kind: Execution
metadata:
name: my-execution
spec:
function: my-function
ttl:
deleteAfter: 7d # Delete 7 days after completion
Optionally, configure archiving to store in a more compact form:
apiVersion: kontinue.cloud/v1alpha1
kind: Execution
metadata:
name: my-execution
spec:
function: my-function
ttl:
archiveAfter: 1d
deleteAfter: 7d # Delete 7 days after completion
| Field | Description | Default |
|---|---|---|
archiveAfter | How long after finishing to archive the execution tree. Creates an ArchivedExecution and deletes the original. | No archiving |
deleteAfter | How long after finishing to delete the execution (or archived execution). | No deletion |
Both TTL and archiving apply only to root executions which are in terminal states (Completed, Failed, Canceled, Skipped). TTL starts upon completion. TTL fields are ignored for child (nested) executions, and children are automatically cleaned up (or archived) with the root execution.
Delete Without Archiving
The simplest cleanup strategy is to delete executions after they complete:
spec:
function: process-data
ttl:
deleteAfter: 24h # Delete 24 hours after completion
This is useful for high-volume workflows where you don’t need to retain history. The execution and all its children are permanently deleted when the TTL expires.
Archive Then Delete
For workflows where you need to retain history, use archiving:
spec:
function: deploy-workflow
ttl:
archiveAfter: 1h # Archive after 1 hour
deleteAfter: 720h # Delete archive after 30 days
When archiveAfter expires:
- The entire execution tree (executions, suspensions, jobs) is serialized and compressed
- An
ArchivedExecutionresource is created containing the snapshot - The original Execution and all children are deleted
When deleteAfter expires:
- The
ArchivedExecutionis deleted
Note: archiveAfter must be less than deleteAfter. If both are set and this constraint
is violated, archiving is skipped and the execution is deleted directly at deleteAfter.
ArchivedExecution
The ArchivedExecution CRD stores a compressed snapshot of completed execution trees:
apiVersion: kontinue.cloud/v1alpha1
kind: ArchivedExecution
metadata:
name: my-execution # Same name as original
spec:
function: deploy-workflow
phase: Completed
originalFinishedAt: "2025-01-15T10:30:00Z"
deleteAt: "2025-02-15T10:30:00Z"
serializedExecution: <gzip+base64 encoded>
serializedTree: <gzip+base64 encoded>
Key fields for querying:
| Field | Description |
|---|---|
function | The function name (for filtering by workflow type) |
phase | Final phase: Completed, Failed, Canceled, or Skipped |
originalFinishedAt | When the execution finished |
deleteAt | When this archive will be automatically deleted |
The serializedExecution and serializedTree fields contain the full execution data
in a compressed format, allowing complete reconstruction if needed.
The kontinue CLI and UI allow viewing archived root executions transparently. Nested
executions are visible when viewing a tree (e.g. via kontinue show) but are not visible
via kontinue list --non-root or via kubectl get execution.
Configuring via Client Library
When spawning an Execution via the client library, pass TTL options in SpawnOptions:
exec, err := client.Spawn(ctx, "my-function", &MyArgs{}, &client.SpawnOptions{
TTL: &kontinuev1alpha1.ExecutionTTL{
ArchiveAfter: &metav1.Duration{Duration: 1 * time.Hour},
DeleteAfter: metav1.Duration{Duration: 7 * 24 * time.Hour},
},
})
Function Defaults
Set default TTL configuration for all executions of a function during registration:
worker.RegisterFunction(w, "process-data", ProcessData, &function.Options{
Description: "Process data with automatic cleanup",
Defaults: &function.ExecutionDefaults{
TTL: &function.ExecutionTTL{
ArchiveAfter: &metav1.Duration{Duration: 1 * time.Hour},
DeleteAfter: metav1.Duration{Duration: 24 * time.Hour},
},
},
})
These defaults apply to all Executions of the function unless overridden at creation time. The defaults are also published to the Function CRD and visible in the UI.