Skip to content

Prevent duplicate runner creates from stale informer lists - #4744

Closed
nikola-jokic wants to merge 1 commit into
masterfrom
nikola-jokic-controller-replica-coordination
Closed

nikola-jokic wants to merge 1 commit into
masterfrom
nikola-jokic-controller-replica-coordination

Conversation

@nikola-jokic

@nikola-jokic nikola-jokic commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Track successful runner creates in a per-set cache until observed by the informer or expired after 60 seconds. Count unseen creates toward capacity without blocking new demand or adding polling.

Includes stale-cache regression coverage and leader-handoff tests. No CRD changes.

Fixes #4722
Fixes #4734

Copilot AI balanced review requested due to automatic review settings November 16, 2026 15:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical cache-expiry bug can leave deleted runners counted indefinitely because unseen creates schedule no reconciliation wakeup, potentially blocking replacement, finalization, and revision cleanup.

1 open issue
What changed in this PR

This PR addresses duplicate runner creation caused by stale informer lists (#4734). It tracks successful creates locally and counts unobserved runners toward capacity without blocking increased demand or changing CRDs.

Changes:

  • Adds per-set creation tracking with 60-second expiry and parent-identity isolation.
  • Integrates tracking into scaling, cleanup, and manager shutdown.
  • Adds stale-cache regression coverage and a shared-lease leader-handoff test.
File Description
main.go Registers creation-cache cleanup on manager shutdown.
controllers/​actions.github.com/​runner_creation_cache.go Tracks successful creates until observation or expiry.
controllers/​actions.github.com/​runner_cache_test.go Tests stale snapshots, expiry, cleanup, concurrency, and partial failures.
controllers/​actions.github.com/​runner_cache_api_test.go Tests interrupted-batch recovery during leader handoff.
controllers/​actions.github.com/​ephemeralrunnerset_controller.go Accounts for unseen creates in scaling and cleanup decisions.
controllers/​actions.github.com/​ephemeralrunnerset_controller_test.go Waits for cached busy-runner status before testing cleanup.

Review effort: Balanced

Comment on lines +82 to +86
for uid, expiresAt := range cached.runners {
if !now.Before(expiresAt) {
delete(cached.runners, uid)
expired++
}

@Okabe-Junya Okabe-Junya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, let me jump in this PR :)

I think this is the read-your-own-writes gap - well-known issue of the k8s cached client - which controller-runtime v0.25 addresses with the experimental EnableReadYourWritesConsistency

(kube-controller-manager took the same approach in KEP-5647 cf. https://www.kubernetes.dev/resources/keps/5647/) I think we would consider using this.

It should also cover deletes (the scale-down half of #4734) and other cached reads, e.g. Secrets if #3825 lands. If its multi-namespace limitation is the blocker (--watch-single-namespace caches two namespaces), I'd appreciated if you noted it in the PR description (or in-tree), since it then constrains any cached read in that mode.

@nikola-jokic

nikola-jokic commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

Hey @Okabe-Junya
Nice! I didn't know this, and it is way better approach! Closing this PR. Thank you for looking into this!

I will revisit this again before the release. There is no need to keep the PR open for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants