Skip to content

Jobs garbage collector runtime

A node leaves Kubernetes Jobs behind as it builds and materialises: one per build, per closure resolution, per control task. The jobs garbage collector removes or expires them under a policy the control plane resolves, and only after the evidence those jobs produced is safe. The node applies the policy and records what it did.

This page covers the three retention modes, the preconditions that hold cleanup back, and the evidence each run produces.

Where the collector sits

flowchart TB
  subgraph CP["CONTROL PLANE"]
    direction TB
    POL[("Resolved jobs garbage<br/>collector policy")]
    EVI[("Evidence and<br/>observability records")]
  end
  subgraph NODE["DATA PLANE NODE"]
    direction TB
    GC{{"Jobs garbage collector"}}
  end
  subgraph NS["WORKSPACE NAMESPACE"]
    direction TB
    JOBS[("Jobs from builds, closure<br/>resolution and control tasks")]
  end
  POL -->|"retention mode, selector,<br/>audit requirements"| GC
  EVI -->|"persisted and committed?"| GC
  GC -->|"patch TTL or delete,<br/>Jobs only"| JOBS
  GC -->|"cleanup evidence"| EVI

Jobs garbage collector acts on one thing, Jobs from builds, closure resolution and control tasks, and only with a policy from CONTROL PLANE. Its own outcome goes back to Evidence and observability records whether or not it touched anything.

The order of checks

flowchart TB
  IN["Resolved policy from the control plane,<br/>namespace, precondition state"]
  EN{{"Policy enabled?"}}
  SEL{{"Selector has labels or refs?"}}
  PRE{{"Audit hold clear,<br/>evidence persisted,<br/>observability commit acknowledged?"}}
  KIND{{"Every selected resource a Job?"}}
  MODE["Apply the retention mode"]
  NR["not_required"]
  NC["not_cleaned"]
  IN --> EN
  EN -->|"no"| NR
  EN -->|"yes"| SEL
  SEL -->|"no"| NC
  SEL -->|"yes"| PRE
  PRE -->|"no"| NC
  PRE -->|"yes"| KIND
  KIND -->|"no"| NC
  KIND -->|"yes"| MODE

Every check that fails ends in not_cleaned with its own reason, and nothing is touched. Apply the retention mode is reached only once the evidence is safe and the selection is known to contain Jobs alone.

The three retention modes

Mode Action Reason code
retain Nothing is deleted or patched; the retention is recorded jobs_garbage_collector_policy_retain
ttl_after_evidence ttlSecondsAfterFinished is patched onto the selected Jobs jobs_garbage_collector_ttl_applied
delete_after_evidence The selected Jobs are deleted jobs_garbage_collector_deleted

ttl_after_evidence with no TTL in the policy uses 600 seconds. Deletion runs in graceful mode by default and in force mode when the request names it. An unrecognised mode is treated as retain, so a policy the node cannot read keeps everything.

The preconditions

Reason code Holds cleanup back when
jobs_garbage_collector_audit_hold The policy places the resources under audit hold
jobs_garbage_collector_evidence_not_persisted Evidence is required and has not been persisted
jobs_garbage_collector_observability_not_committed An observability commit is required and has not been acknowledged

Evidence and observability commits are required unless the policy says otherwise. Evidence counts as persisted when its state reads persisted, committed or acknowledged, or, where no state is given, when it carries an immutable identity: an artifact digest, manifest digest, snapshot digest or resolved revision digest.

The selection

A policy selects by labels, by explicit references, or both. Labels are resolved against the namespace, explicit references of kind Job are added, and every other kind in the references is collected as unsupported. One unsupported reference fails the whole run with jobs_garbage_collector_resource_kind_not_allowed and names the references, so a policy written to reach a Deployment or a Secret stops at the first run.

A selector with neither labels nor references fails with jobs_garbage_collector_selector_empty, because an empty selector is a policy error.

The evidence each run produces

Every outcome is a system.jobs_garbage_collector_runtime_evidence.v1 record, including the ones that touched nothing:

{
  "contract_version": "system.jobs_garbage_collector_runtime_evidence.v1",
  "namespace": "xr-ws-orders",
  "policy_version": "system.jobs_garbage_collector.policy.v1",
  "enabled": true,
  "retention_mode": "delete_after_evidence",
  "ttl_seconds": 0,
  "status": "completed",
  "reason_code": "jobs_garbage_collector_deleted",
  "cleanup_reason_code": "jobs_garbage_collector_deleted",
  "selected_jobs": 4,
  "deleted_jobs": 4,
  "patched_jobs_ttl": 0,
  "cancellation_mode": "graceful",
  "desired_generation": 2,
  "observed_generation": 2,
  "finalization_evidence_refs": ["ev-7c41..."],
  "resource_selector": { "labels": { "xratu.io/assignment-id": "asg-71c4..." }, "refs": [] },
  "audit_requirements": { "evidence_required": true, "observability_commit_required": true },
  "precondition_state": { "evidence_persisted": true, "observability_commit_acknowledged": true }
}
Status Means
not_required The policy has collection disabled
retained The policy retains, and nothing was changed
not_cleaned A check failed, and nothing was changed
completed The retention mode was applied