Assert icon
If icon
Get icon
Request icon
Toggle icon
Delete icon
List icon
GetKeys icon
OutputValues icon
Loop icon
Count icon
Log icon
Set icon
Pause icon
Schedule icon

Retire Unused Kestra Flows with Quarantine, Approval and Restore

Find unused Kestra flows, quarantine them by disabling their triggers, and delete them after approval with a backup you can restore in one run.

Categories
Infrastructure

Namespaces collect flows nobody runs any more: old reports, replaced pipelines, one-off migrations. Deleting them by hand is risky, because some are still called as subflows or listened to by Flow triggers, and some run only once a year. This blueprint retires them in two reversible steps, keeps a restorable copy of every flow it deletes, and backs off as soon as a flow turns out to be in use.

How it works

  1. The weekly_review schedule, or a manual run, reviews one namespace. A manual run is a dry run by default.
  2. flows, candidates and review_candidates list the namespace's flows, skip those labelled retirement: keep, and keep only flows with no execution and no edit during idle_period and no dependent flow in the Kestra dependency graph (a subflow caller, or a flow listening with a Flow trigger).
  3. Each such flow is quarantined: its triggers are disabled, and its source and quarantine time are saved in the KV store.
  4. review_quarantined checks every quarantined flow again. If it ran or gained a dependent since its quarantine, its triggers are switched back on and its retirement is cancelled. Once quarantine_period is over, it is marked ready.
  5. approval pauses for up to a day. On resume, delete_ready archives each ready flow's source for 180 days, deletes the flow and checks that the API now answers 404. Without approval, nothing is deleted.
  6. Running with restore_flow_id re-creates a deleted flow from its archive, or releases a quarantined one, switches its triggers back on and clears its records.

What you get

  • A dry-run report of unused flows before anything changes.
  • Two reversible stages, quarantine then deletion, with a human approval before any delete.
  • Automatic cancellation when a quarantined flow is used again or gains a dependent.
  • A 180-day archive of every deleted flow and a one-input restore.
  • State kept in the KV store, so each weekly run continues where the previous one stopped.

Who it's for

  • Platform teams running Kestra for many teams.
  • Data engineers cleaning up namespaces after migrations.

Why orchestrate this with Kestra

  • The review, the approval and every deletion are recorded in the execution history.
  • The Kestra plugin and API give exact execution counts, trigger control and the dependency graph, so nothing is guessed from naming conventions.
  • Pause makes the destructive step wait for a person, and the KV store carries the state between weekly runs.

Prerequisites

  • Kestra 2.0 or later with the Kestra plugin.
  • A Kestra user allowed to read executions and to read, update and delete flows and triggers in the reviewed namespace.
  • This flow must live outside the reviewed namespace and its parents.
  • Label flows that run rarely on purpose, such as disaster-recovery runbooks, with retirement: keep.

Secrets

  • KESTRA_USERNAME: Kestra API user that lists, counts, toggles, deletes and re-creates flows.
  • KESTRA_PASSWORD: password of that user.

Quick start

  1. Add both secrets to the company.platform namespace.
  2. Set the namespace and kestra_url defaults, and adjust idle_period and quarantine_period if needed.
  3. Execute the flow manually with the default dry_run: true and read the report in the logs.
  4. Enable the schedule. It runs with dry_run: false, quarantines candidates and asks for approval once some are ready.
  5. Resume the paused execution to delete the flows listed in the ready task's outputs, or run with restore_flow_id to bring one back.

How to extend

  • Send the dry-run report and the approval request to Slack or Teams.
  • Loop over several namespaces, each with its own idle period.
  • Push the archived sources to Git with PushFlows for a permanent record.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.