Skip to content

feat(kubernetes): replace agents built from an outdated pod template (RIG-7278) - #22

Merged
mattwilkinsonn merged 7 commits into
rigel-releasefrom
ci-pipelines/rig-7278-template-hash
Nov 2, 2026
Merged

mattwilkinsonn merged 7 commits into
rigel-releasefrom
ci-pipelines/rig-7278-template-hash

Conversation

@rigel-mintaka

@rigel-mintaka rigel-mintaka commented Nov 1, 2026 •

Copy link
Copy Markdown

Summary

  • The Kubernetes provider builds its agent pod from a template read once at start. After a template or config change, live agents keep the old spec until they scale down. On a pool with MIN_AGENTS > 0 that can be hours, which is how the CD pool ran stale agents during the RIG-7278 outage.
  • The provider hashes the effective agent pod (template plus config image fallback and env), stamps it as wp.autoscaler/template-hash, and reports pool pods whose hash is missing or different through a new optional types.OutdatedAgentLister. Other providers and the mocks are untouched.
  • Each Reconcile drains outdated agents before capacity planning, so they count as unavailable: replacements deploy in the same pass and scale-down only picks current agents.
  • createAgents never reactivates an outdated agent, and caps new agents at MaxAgents minus every pool agent row, so a rollout replaces busy agents as they finish instead of doubling the pool.
  • removeDrainedAgents retires an outdated agent once it has no tasks; the warm-idle LastWork timeout does not apply, because it is never reused.

Rollout behavior

  • At MaxAgents, an outdated agent's slot is refilled on the reconcile after its removal (default interval 1m).
  • Scaler deployments in the consuming repo run replicas: 1, so two scaler versions do not drain each other's agents.

Tests

  • go test ./..., go vet ./..., gofmt -l, golangci-lint run on engine + providers/kubernetes are clean.
  • New: hash stamping, effective-pod hash (config image change), outdated listing and its list-error path (providers/kubernetes); Test_drainOutdatedAgents (drain, no-op provider, update error, lister error stops reconcile, MinAgents=1 replace-before-retire with event order, multi-reconcile rollout at MaxAgents); Test_createAgents (no reactivation, MaxAgents cap); Test_isAgentIdle (outdated bypass).
  • Mutation-checked: each regression test fails with its fix reverted.

Spec-impact: none

Refs RIG-7278

…(RIG-7278)

The provider reads its agent pod template once at start. After a
template change, agents that already exist keep the old env until they
happen to be scaled down. With MIN_AGENTS above zero that can be hours.

The provider now stamps a template hash on each agent pod and reports
pods whose hash differs. Each reconcile drains those agents. They are
removed once idle, and scale-up deploys fresh agents rather than
reactivating them.

Refs RIG-7278

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@linear-code

linear-code Bot commented Nov 1, 2026

Copy link
Copy Markdown

RIG-7278

rigel-mintaka and others added 6 commits November 1, 2026 18:52
…RIG-7278)

An empty template image falls back to config.Image, and config also
adds env. Hashing only the template missed those changes, so agents
built from an old config were never marked outdated.

Refs RIG-7278

Co-authored-by: Matt Wilkinson <matt@rigel.build>
…IG-7278)

Refs RIG-7278

Co-authored-by: Matt Wilkinson <matt@rigel.build>
Draining after calcAgents counted outdated agents as capacity. With
MinAgents=1 no replacement was deployed before the old agent was
removed, and scale-down could drain a current agent too. Never-contacted
outdated agents are drained as well, since they hold no work.

Refs RIG-7278

Co-authored-by: Matt Wilkinson <matt@rigel.build>
Drained outdated agents may still run work, and their pods stay until
removed. createAgents now caps new agents at MaxAgents minus every pool
agent, so a rollout replaces busy agents as they finish rather than
doubling the pool. The reconcile test also pins deploy-before-remove.

Refs RIG-7278

Co-authored-by: Matt Wilkinson <matt@rigel.build>
A drained outdated agent is never reused, so the warm-idle timeout only
kept its MaxAgents slot from its replacement. removeDrainedAgents now
removes an outdated agent as soon as it has no tasks. createAgents logs
the capped count it actually starts. A multi-reconcile test covers a
rollout at MaxAgents.

Refs RIG-7278

Co-authored-by: Matt Wilkinson <matt@rigel.build>
Refs RIG-7278

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@rigel-mintaka

Copy link
Copy Markdown
Author

Review note: head 9b37bbe

  • Fan-out review (correctness, design, style) ran over 4 rounds. 0 high / 0 medium at 5b4d58b. 9b37bbe only rewords the cap comment, per that round's style finding.
  • Fixed along the way:
    • Outdated agents were reactivated in a loop.
    • The hash covered only the raw template, missing the config image and env.
    • Drain ran after planning, which broke MinAgents and scale-down.
    • Rollout could exceed MaxAgents.
    • The warm-idle timeout blocked replacement.
    • Error-path, ordering and multi-reconcile tests were missing.
  • Rebutted, and accepted by the reviewer: provider-only pods during the dangling grace are not counted by the cap. That was already true of upstream calcAgents, and this PR does not widen it.
  • Accepted lows not fixed:
    • At MaxAgents a freed slot refills one reconcile later (default 1m).
    • Two scaler versions overlapping could churn; orion runs replicas: 1.
  • CI: check and CI (pr) pass. CI (meta) is the Woodpecker release workflow waiting for a backend: docker agent that doesn't exist. It is not required, it is pre-existing (chore(release): 1.5.0-rigel.3 (RIG-5997) #21 errored the same way), and RIG-7324 tracks it.
  • Local: go test ./..., go vet, gofmt, golangci-lint are clean. Each regression test was mutation-checked.

@rigel-mintaka
rigel-mintaka marked this pull request as ready for review November 2, 2026 00:48
@mattwilkinsonn
mattwilkinsonn merged commit 68e7eb7 into rigel-release Nov 2, 2026
3 of 4 checks passed
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.

2 participants