All case studies

Automation

Rebuilding a cleanup job that couldn’t say “not this one”

Short-lived demo environments on a shared EKS cluster were cleaned up by two separate automations. One failed 220 times a day. The other destroyed an environment marked do-not-delete.

Stack
Python, Elastic Load Balancing, EKS, ECS, PostgreSQL, cron, a workflow-automation tool
My role
Audit, rewrite and rollout
Outcome
A replacement that dry-runs by default is running in production, on an instance role, with audit logs and tag protection.

What I found

I traced the second chain end to end: the automation’s schedule, then the internal API, then the destroy job and its parameters. That told us exactly which build removed the protected environment, and why nothing had stopped it.

The rewrite

Rolling it out

The first dry run sorted the environments into three groups: 8 ready, 5 blocked, 1 protected. The blocked ones mattered most. Four had database rows with a doubled name suffix, and their resource maps pointed at target groups belonging to live environments. Cleaning those up through AWS would have taken down sandboxes people were using. They are only marked in the database.

The first --apply ran against a single environment, and I checked the result. Then the new cron went live, and the old one was disabled.

What I took from it

  • A cleanup job needs a way to say “not this one” that isn’t a list in code.
  • Dry run first, by default, every time. The first dry run here caught the four cases that would have caused an outage.
  • Read the real state from the provider. Your own bookkeeping drifts.