Delete a rig that has been idle for 30 minutes

A rig deletes itself once nothing has used it for 30 minutes in a row, whether or not a worker ever tore it down.

What changes

  • A systemd timer on the VM runs an idle check every 5 minutes, from first boot. The check script is gce/idle-delete.sh; up hands it to the VM as instance metadata, and startup.sh installs it.
  • Busy means any of: an established sshd connection (IAP included), a process whose command line carries sim-job, or a startup script that has not reported done while the VM is under an hour old. Any probe that fails counts as busy.
  • The first idle check records the time. A busy check clears it. At 30 idle minutes the VM deletes itself through the compute API with its own service account token. The first-idle time and the delete go to the serial log, and the first-idle time is also a guest attribute while the VM lives.
  • startup.sh installs sim-job <command>, a wrapper that stays the parent of a long job so the marker survives bash exec. The detached bootstrap launches in simulation.sh and the crc start in openshift-local.sh carry the marker.
  • up --budget <time> sets the max run to the budget plus 1h. GPU rigs default to 2h and stay at 2h unless --max-runtime extends them. An explicit --max-runtime still wins, and the 12h ceiling stands.
  • gce/operations.md tells coordinators to run down on a worker's rigs when the worker returns or goes quiet, and tells workers to check that the VM still exists before each wait.

Self-delete permission

The VM runs as the default compute service account with the cloud-platform scope. In this project that account holds Editor, which includes compute.instances.delete, so nothing was granted. In a project where the account lacks it, it needs compute.instances.delete on its own instance. No scope was widened and no role added.

Idle check

flowchart TD
    T["Timer fires every 5 min"] --> B{"Busy? sshd connection, sim-job process,<br/>or startup script unfinished"}
    B -- "yes, or any probe fails" --> C["Clear first-idle time"]
    B -- "no" --> F{"First-idle time recorded?"}
    F -- "no" --> R["Record first-idle time"]
    F -- "yes" --> M{"Idle 30 min or more?"}
    M -- "no" --> W["Wait for next tick"]
    M -- "yes" --> D["Delete this instance through the compute API"]

Proof

Both arms ran on GCE with the cheapest dev-base rig that runs the timer. The timestamps are added in a comment below.

Tests

gce/idle-delete-selftest.sh runs the check against stubbed ss, pgrep, curl and logger, including the 29 and 31 minute boundaries, a refused delete, the startup grace and an unreadable clock. gce/engine-selftest.sh covers --budget, the GPU cap and the metadata hand-off. scan-accept.yml counts and reasons cover the new idle-check signatures.

Merge request reports

Loading
Loading