Script icon
Docker icon
Get icon
Set icon
Log icon
If icon
Pause icon
Loop icon
Patch icon
Write icon
Delete icon
Sleep icon
Fail icon
Schedule icon
SlackIncomingWebhook icon

Archive ownerless failed Pod diagnostics before cleanup

Archive ownerless failed Pod status diagnostics after a termination or observation hold, pin identity during cleanup and verify removal.

Categories
Infrastructure

How it works

Native Get reads namespace Pods. Only ownerless Failed Pods labelled diagnostics.example.com/collect=true qualify. Succeeded, active, mirrored and foreign-finalized Pods stay protected.

Complete container terminated.finishedAt timestamps anchor retention. When these are missing, a UID-keyed first-observed-Failed hold starts instead. Creation time and startTime never age a failure. A capped plan feeds explicit approval in live mode.

A native JSON Patch checks UID/resourceVersion and adds a collector finalizer. This pins the old name across Delete. Status diagnostics are archived in internal storage and read back by SHA-256 before Delete. The flow requires a deletionTimestamp, conditionally releases its sole finalizer then fails if the old UID survives.

What you get

  • A retained diagnostic JSON archive and UID-bound KV receipt.
  • Verified removal of eligible failed API records, with partial cleanup reconciliation.

Who it's for

Platform teams using ownerless one-off Pods whose failed records must outlive an investigation hold.

Why orchestrate this with Kestra

Keep the approval, diagnostic archive and identity-pinned deletion in one execution. PodGC is threshold-based; this is opt-in diagnostic retention below that threshold.

Tested end to end

On Kestra 2.0.6 and 2.0.5 with Kubernetes plugin 1.11.5/1.11.4 and k3s 1.31.5, 59 executions checked healthy, dry, declined, removal, denied Delete, retry and races. Each suite fixture removed one Failed Pod while three protected records survived. Eleven archive receipts verified 47730 bytes through the API. A real Evicted Pod without finishedAt stayed through a 20-second observation hold and was collected after expiry. A fresh cluster repeated the full suite and independent checks.

Prerequisites

Kubernetes API access and get/list/patch/delete Pods in one namespace. Docker runs bounded Python transforms. Reserve the collector finalizer for this flow. Privileged status writers must not reactivate pinned failed Pods. QUEUE/1 serializes this flow only; other copies compete at the resourceVersion test. External finalizers block cleanup.

Secrets

K8S_MASTER_URL, K8S_TOKEN, K8S_CA_CERT_DATA and SLACK_WEBHOOK_URL. Token is a SECRET input. TLS verification is enabled by default.

Inputs

Select cluster_id and namespace; default retention is 86400 seconds, deletion cap five and inventory cap 1000. max_archive_bytes caps each archive at 262144 bytes. dry_run=true and auto_remediate=false keep cluster state unchanged; observation KV is updated.

Quick start

  1. Set secrets and namespace-scoped RBAC. Label only expendable ownerless Pods.
  2. Run safe mode and review held, eligible and deferred counts.
  3. After the hold, run live mode and explicitly approve. Inspect archive receipts and API absence.
  4. Enable the disabled schedule for report-only scans.

How to extend

Copy verified archives to your retention store before execution history is purged.

Limits: metadata/status diagnostics are preserved, not container logs, mounted data or node cleanup evidence. Missing finish timestamps produce a conservative observation hold, not a claimed eviction time. The plugin lists the whole namespace before the inventory ceiling is checked. After interruption, rerun to rearchive and reconcile the pinned old UID. Never remove the finalizer manually without verifying diagnostics. No blanket write retries. Labels, owners, status and foreign finalizers must remain unchanged while the collector pin exists. Identity is pinned across name reuse, but this is not atomic eligibility against privileged external writers. The pre-delete read and conditional release detect drift; enforce that cooperative writer contract through namespace ownership. Storage retention follows execution history, so export archives before purge. Optional null fields can be omitted by the plugin serializer.

Links

This blueprint was created by zkasuran.

See How

New to Kestra?

Use blueprints to kickstart your first workflows.