Repository navigation
Drain gate: strip the runner's custom labels so it takes no new jobs - #59
Conversation
The drain only polled `busy`, so on a busy fleet the runner picked up a new queued job each time it finished one and the deploy timed out after github_runner_drain_timeout_minutes. When a replace is imminent, record and strip the runner's custom labels first, then wait out the in-flight job. The replacement registers with its configured labels; a failed drain (no replace) puts the stripped labels back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The strip-labels loop omits the default([]) guard used elsewhere, so the drain gate errors on an undefined variable when no registered runner matches the name.
1 open finding
What changed in this PR
This PR fixes the drain-before-replace gate in the github_runner Ansible role. Previously the gate only polled the runner's busy flag, so on a busy fleet the runner kept accepting newly queued jobs and never went idle, causing deploys to time out after github_runner_drain_timeout_minutes. The fix strips the runner's custom labels (via the GitHub labels API) when a replace is imminent so no new jobs route to it, waits out the in-flight job, then replaces it; a failed drain restores the stripped labels.
Changes:
- Added
Record/Striptasks to capture andDELETEa matching runner's custom labels before polling for idle, plus a rescue step that restores them via the newtasks/restore_labels.yml(PUT). - Split the runners API URL into
github_runner_api_runners_base(no query string) so per-runner label endpoints can be built, keepinggithub_runner_api_runners_urlfor the paginated listing. - Bumped version to 0.1.7 and updated README/CHANGELOG to document the new behavior and the label-management token requirement.
| File | Description |
|---|---|
| roles/github_runner/tasks/main.yml | Adds record/strip-labels tasks before the idle poll and a rescue step to restore labels on drain failure; updates the drain comment. |
| roles/github_runner/tasks/restore_labels.yml | New task file that PUTs the recorded custom labels back when the drain fails. |
| roles/github_runner/vars/main.yml | Introduces github_runner_api_runners_base and derives github_runner_api_runners_url from it. |
| README.md | Updates the github_runner_drain_before_replace description for the label-stripping behavior and token requirement. |
| galaxy.yml | Bumps role version to 0.1.7. |
| CHANGELOG.md | Documents the 0.1.7 drain-gate fix. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Problem
The drain-before-replace gate (0.1.5) only polls the runner's
busyflag. On a busy fleet the runner picks up the next queued job each time it finishes one, so the gate never sees it idle and the deploy fails aftergithub_runner_drain_timeout_minutes. Seen on BumpApp/bump: an infra merge to main queued ~12 test workflows onto the same runners the deploy was draining, and silverstone's JVM runner timed out after 45 min.Change
When a replace is imminent:
DELETE /actions/runners/{id}/labelsso no new job can route to it (the in-flight job is unaffected).PUTthe recorded labels back (tasks/restore_labels.yml) so the old runner takes jobs again.Read-only labels (
self-hosted, OS, arch) can't be removed, so a job targeting only those can still land on a draining runner (noted in the CHANGELOG).Also:
github_runner_api_runners_base(the URL without?per_page=100) for the per-runner label endpoints; version 0.1.7; CHANGELOG + README.Testing
ansible-lint26.4.0: passes, production profile.The token needs to be able to manage runners (classic
admin:orgfor org runners, which the existing listing already requires).🤖 Generated with Claude Code