Skip to content

Track runner expectations so EphemeralRunnerSet never scales from a stale cache - #4735

Open
jia-pylon wants to merge 1 commit into
actions:masterfrom
jia-pylon:fix/ephemeralrunnerset-expectations
Open

jia-pylon wants to merge 1 commit into
actions:masterfrom
jia-pylon:fix/ephemeralrunnerset-expectations

Conversation

@jia-pylon

Copy link
Copy Markdown

Fixes #4734

What

The EphemeralRunnerSet controller now remembers the runners it has created or deleted until its informer cache shows them. Before that happens, it does not make another scale or cleanup decision for that set. This is the controller-expectations pattern from kube-controller-manager's ReplicaSet controller, scaled down to what ARC needs.

  • runnerExpectations (new, runner_expectations.go) is a small, mutex-protected type keyed by the set's namespace/name and owner UID. It records the server-generated name of each successful create, and the name of each successful delete (or a NotFound / already-terminating result).
  • Each reconcile still uses the existing cached resourceOwnerKey list. That list is checked against the recorded names: a create counts as seen once its name appears, and a delete once its name is gone or has a deletionTimestamp. A set does not wait for runner finalizers, and terminating runners still block scale-up through the existing deleting count.
  • While any name is still unseen, the controller skips every reconcile branch that creates or deletes runners: scale up, scale down, finished-runner cleanup, revision/outdated cleanup and owner finalization. It requeues after 1s. Proxy-secret reconciliation and status updates continue on the normal path.
  • Pending names expire after 5 minutes, with a log line, so a lost watch event cannot block a set forever. State is cleared when the set is deleted or its UID changes.
  • The change adds no API-server reads and no informer event handlers.

Why

See #4734. A reconcile woken by the controller's own status patch, or by the first child's add event, can count too few runners and create a second batch. In unmodified envtest runs on master this happened in 21 of 24 full-suite runs (kube-apiserver 1.35/1.36/1.37), e.g. 9 runners created for replicas: 5 before scale-down removed the extras.

I also considered listing children through APIReader on every reconcile. It fixes the race, but it reads every EphemeralRunner in the namespace on every child event, which patchAppliedActionableRevisionStatus already notes is only acceptable on rare paths.

Tests

  • ephemeralrunnerset_cache_lag_test.go: deterministic regressions with a client whose List omits recent writes. They cover scale-up, scale-up blocked behind deletes, scale-down, and filtering by ownership. On master they fail (4 runners for replicas: 2, plus surplus deletes) and with this change they pass.
  • runner_expectations_test.go: observation, delete observation by absence and by deletionTimestamp, TTL expiry, UID change, concurrent owners, failed writes not recorded.
  • ephemeralrunnerset_expectations_test.go: cleanup and finalization are gated, no authoritative list is needed, and state is cleared after deletion.
  • autoscalingrunnerset_cache_lag_test.go: pins that a repeated EphemeralRunnerSet create from the AutoscalingRunnerSet controller is rejected by its fixed name, so that path needs no expectations.

Full controllers/actions.github.com suite, 10 runs per kube-apiserver version with this change:

kube-apiserver runs failures over-creates in logs
1.35.0 10 0 0
1.36.2 10 0 0
1.37.0 10 0 0

go build ./... and go vet ./controllers/... are clean. golangci-lint reports the same five findings as master and no new ones.

Wait for cached child lists to observe successful creates and deletes before scaling or cleaning up a runner set. Track generated runner names per owner UID, observe deletion timestamps without waiting for finalizers, and expire missing observations after five minutes.

Continue safe status and proxy-secret reconciliation while waiting, and requeue to recover from lost watch events. Add deterministic lagging-cache regressions and tests for expectation lifetime, failed writes, ownership changes, and cleanup gating.

This branch has not been deployed

No deployments
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.

EphemeralRunnerSet controller creates more runners than spec.replicas when its cache lags its own creates

1 participant