Skip to content

feat(controller): serve several runner images from one controller - #57

Merged
parsilver merged 8 commits into
mainfrom
feat/15-serve-several-runner-images
Nov 26, 2026
Merged

parsilver merged 8 commits into
mainfrom
feat/15-serve-several-runner-images

Conversation

@parsilver

@parsilver parsilver commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #15

One controller now serves several runner images. RUNNER_POOLS is a JSON list of pools, each with a label, image, prefix, max_runners, scopes and an optional region. Each cycle reads every scope once, whichever pools list it, and gives each queued job to the pool whose label it asks for. The canTake rule, run across the pool labels, decides that. reconcile.Make then runs once per pool, with that pool's own services, jobs and maximum. The single-pool variables still configure one pool unchanged.

Acceptance

  • One cycle with jobs for two labels creates services from the right image and prefix for each, and makes one set of GitHub list calls per scope. TestOneCycleServesEveryPoolFromItsOwnImageAndPrefixWithOneScanPerScope checks the image, prefix, JIT label and region of each service. It also checks one QueuedJobs and one Runners call per scope, including a scope that two pools list.
  • A pool at its maximum does not block the other pool. TestAPoolAtItsMaximumDoesNotBlockTheOtherPool. Isolation is also covered by TestAPoolNeverReapsOrCountsAnotherPoolsServices, TestAnIdleRunnerOfOnePoolIsNoSupplyForTheOtherPool and TestAnExitedServiceIsReapedOncePerCycle.
  • A webhook queued event for either label starts a cycle. TestAQueuedWebhookForEitherPoolsLabelStartsACycle in the controller and TestAQueuedJobWithAnyPoolLabelNudgesTheController in the webhook. Labels now match without case, as the job scan already did.
  • Existing single-pool configuration loads unchanged (one pool). TestTheSinglePoolVariablesLoadAsOnePool. The existing config tests pass with only the field paths changed.
  • Service prefixes of different pools cannot overlap. TestRunnerPoolsIsRefusedWhenMalformedNamingTheVariable covers a shared prefix, a shared label (compared without case), the reserved labels, and malformed pools. The existing prefix rule already stops one prefix from being the start of another. TestRunnerPoolsCannotBeMixedWithTheSinglePoolVariables covers setting both kinds of configuration at once.
  • Deploy docs describe the pool list and no longer describe a second controller. README has a "Several pools" section. docs/deploy.md rewrites the Postgres pool as a second RUNNER_POOLS entry and adds "Moving from two controllers to one". grep -i "second controller" README.md docs/deploy.md finds nothing.

An independent plan review found these gaps, now fixed and tested:

  • Late-job alert marks are cleared once across every pool, so a scope shared by two pools does not re-alert a job (TestALateJobIsAlertedOnceWhenTwoPoolsShareItsScope).
  • Another pool's new runner does not hide a late job (TestAnotherPoolsNewRunnerDoesNotHideALateJob).
  • A scope that two pools share and that cannot be read counts once, and its services are left alone (TestAnUnreadableSharedScopeCountsOnceAndNoPoolTouchesItsServices).
  • Each pool can set its own region, so a Postgres controller that ran in another region keeps it after the move.

Commands run

$ go vet ./...
$ go test -race -count=1 ./...
?   	github.com/farzai/github-runner-railway/cmd/controller	[no test files]
ok  	github.com/farzai/github-runner-railway/internal/config	1.417s
ok  	github.com/farzai/github-runner-railway/internal/controller	3.003s
ok  	github.com/farzai/github-runner-railway/internal/ghapp	7.114s
ok  	github.com/farzai/github-runner-railway/internal/railway	1.493s
ok  	github.com/farzai/github-runner-railway/internal/reconcile	1.400s
ok  	github.com/farzai/github-runner-railway/internal/webhook	1.445s
$ python .quality/gate.py --base origin/main --description-html <the waivers below>
Waivers: pass, Format: pass, Coverage: pass, CRAP: pass, Duplication: pass, Mutation: pass

Gate numbers

  • Coverage: repo lines at 90.92%, up from 89.19%. .quality/baseline.json is updated. Every changed line is covered except four wiring lines in func main, which are waived below.
  • CRAP: 43 changed functions scored, and every new one is under 10. Four were already over 10 and score no higher: main 56 (base 56), Load 17 (base 25), parseScope 11 (base 11), alertLate 14 (base 17).
  • Duplication: no pair at 0.8 or above.
  • Mutation: 94 killed, 1 survived on the changed lines. The survivor is the slice capacity hint, waived below.

Waivers

Equivalent mutant: cmd/controller/main.go:29 wiring inside func main, which no test can run; the labels it passes come from Config.Labels, which the config tests cover

Equivalent mutant: cmd/controller/main.go:34 wiring inside func main, which no test can run; the prefixes it passes come from Config.Prefixes, which the config tests cover

Equivalent mutant: cmd/controller/main.go:46 wiring inside func main, which no test can run; the controller tests build the same Config with pools

Equivalent mutant: cmd/controller/main.go:52 wiring inside func main, which no test can run; the webhook and controller tests cover a handler given every pool label

Equivalent mutant: internal/config/config.go:33 only the capacity hint of a slice that append grows anyway, so no output changes

Risks

  • This runs the production runners. An existing single-pool deployment needs no change: the same variables load to the same pool. Two behaviours change for every deployment. The webhook matches labels without case, so a runs-on: Railway job now wakes the controller sooner; before, it waited for the poll. A label of self-hosted, linux or x64 is refused at start; such a label could never route jobs correctly anyway.
  • Moving from two controllers to one: stop the Postgres controller before the pooled controller manages its prefix, because two controllers on one prefix would reap each other's runners. The deploy doc gives the order.
  • Removing a pool from RUNNER_POOLS strands its leftover services, since its prefix is no longer listed. The docs say to drain a pool first.
  • MAX_CREATE_PER_CYCLE now applies per pool, so N pools can create up to N times that many services in one cycle. Railway calls rise by the same factor in a burst.
  • Rollback: redeploy the previous controller image with the single-pool variables, and start the second controller again if one was used.

Not verified

  • No live deploy. Routing, isolation and the webhook are proven by unit tests against fakes, not by a cycle against real GitHub and Railway. The first pooled deploy should be watched: the controller up line should list both pools, then jobs of both labels should get runners.
  • I did not build the Docker images locally. The controller's Dockerfile is unchanged, and CI builds the images.

Failing tests for issue #15: pools routed by label, one GitHub scan per
scope, pools isolated from each other, RUNNER_POOLS config with the
single-pool variables as a shorthand, and a webhook for any pool label.
They do not compile yet: the pool type and the new signatures land next.
A job is routed to the one pool label it asks for (canTake, without
case), a JIT runner carries the label of its pool, Railway lists every
pool's services in one listing and creates each from its pool's image
and region, and the webhook wakes the loop for any pool label.

Proved by the ghapp, railway and webhook tests (go test -race).
One JSON list of pools (label, image, prefix, max_runners, scopes and an
optional region). The single-pool variables still load as one pool, and
mixing the two is refused. Prefixes and labels must differ across pools
so no pool can reap another's services or share its jobs.

Proved by the config tests.
Each distinct scope is read once per cycle and each pool is planned
from its own services and the jobs that ask for its label, so a pool at
its maximum never blocks another. Alert marks are cleared once over all
pools so a shared scope cannot re-alert a late job.

Proved by the controller tests (go test -race ./...).
Kills the mutants on the new number and pool bounds, covers a failed
reap and the per-cycle floors, splits RUNNER_POOLS parsing to keep CRAP
under 10, folds Labels and Prefixes into one helper, and records the
higher coverage baseline.

Proved by the quality gate run locally: every check passes.
README and docs/deploy.md describe RUNNER_POOLS, the rules across
pools, draining a pool before removing it, the per-pool create limit,
and how to fold a separate Postgres controller into the main one.

Checked: no mention of a second controller is left in README.md or
docs/deploy.md, and README documents RUNNER_POOLS.
Each pool counts its own jobs now, so the cycle-wide count was filled
and never read. Proved by go vet and go test -race.
Kills the last mutant on the per-cycle floor. Proved by the quality
gate run locally.
@parsilver
parsilver marked this pull request as ready for review November 26, 2026 05:46
@parsilver

Copy link
Copy Markdown
Contributor Author

Reviewed: approve. The single-pool variables load exactly as before (same default prefix, same reaping), each pool only sees its own prefix, there is one list call per scope per cycle, and /healthz still reports last_success. The race tests are clean.

Nits for a follow-up:

  • canTake: check label != "" before comparing, so an empty job label is rejected as it was before.
  • The two-controllers-to-one guide in docs/deploy.md:
    • Rollback: start the old Postgres controller only after the rolled-back main deploy is live.
    • List the per-controller settings that become shared (POLL_SECONDS, RUNNER_GROUP_ID, grace and idle TTLs, MAX_CREATE_PER_CYCLE, runner project and token).
    • Say the steps apply to any extra controller, e.g. the PHP one.
    • Validate the RUNNER_POOLS JSON before stopping the extra controllers.
  • Duplicate scopes across pools are not removed; now that this is easier to do, dedupe them.

@parsilver
parsilver merged commit 27592a3 into main Nov 26, 2026
29 of 30 checks passed
@parsilver
parsilver deleted the feat/15-serve-several-runner-images branch November 26, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

controller: serve several runner images from one controller, routed by label

1 participant