Skip to content

Release AutoscalingRunnerSet deletion when the GitHub config secret is gone - #4688

Merged
nikola-jokic merged 6 commits into
actions:masterfrom
ankit373:fix/ars-deletion-missing-secret
Sep 30, 2026
Merged

nikola-jokic merged 6 commits into
actions:masterfrom
ankit373:fix/ars-deletion-missing-secret

Conversation

@ankit373

@ankit373 ankit373 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4655

Problem

When the githubConfigSecret is deleted before its AutoscalingRunnerSet, deleteRunnerScaleSet can't build an Actions client, so it returns that error. cleanUpResources and Reconcile pass it up and the finalizer is never removed. The AutoscalingRunnerSet then stays in Terminating forever, and so does any helm uninstall or namespace deletion waiting on it.

Today that error can't be told apart from a transient failure, because secretresolver formats the underlying error away: failed to get kubernetes secret: %q drops err, and GetActionsService wraps with %v. With Azure Key Vault, a missing secret comes back as an azcore.ResponseError, which is not a Kubernetes error at all.

Fix

  • secretresolver.ErrNotFound: a new exported sentinel of type secretResolverError, as suggested in review. Each driver wraps its own "missing" error with it:

    • Kubernetes: a Kubernetes NotFound for the GitHub config secret, the proxy credential secret, the vault proxy secret or the TLS config map.
    • Azure Key Vault: an azcore.ResponseError with StatusCode == 404 and ErrorCode == "SecretNotFound". Both are checked, so a missing vault, a 403 or a throttled read still requeues.
  • The resolver's %v wraps become %w, so the sentinel and the original error both survive the chain.

  • deleteRunnerScaleSet: on errors.Is(err, secretresolver.ErrNotFound) it does three things:

    • logs at Error level with the runnerScaleSetId, saying the scale set must be deleted manually from the Actions service;
    • removes the runner-scale-set-id annotation;
    • returns nil, so the finalizer is released.

    This matches the existing contract for a manually removed annotation. The annotation patch moved into a small helper that both paths share.

  • Every other error (invalid secret contents, Forbidden, API server errors, vault throttling, Actions 5xx) is still returned and requeued.

Notes for review:

  • No other callers change behaviour. Switching %v to %w exposes Kubernetes errors to every caller of GetActionsService and GetAppConfig. I checked all of them in the four controllers and the unregistration queue: none branches on IsNotFound or IgnoreNotFound for a resolver error. The IgnoreNotFound calls apply only to each controller's own Get of the reconciled object.
  • No Kubernetes Event. The actions.github.com controllers have no event recorder today, and the controller chart only grants events in the leader-election role. Adding one would need main.go wiring and RBAC changes in both charts, which seemed out of scope. Happy to add it if you want it here.
  • EphemeralRunnerSet and EphemeralRunner are out of scope. Their finalizers can also fail to build a client while registered runners exist. Changing that affects live runner pods, so I left it for a separate discussion. The listener and ephemeral runner set cleanup steps in this controller only touch Kubernetes objects, so they can't wedge this way.

Tests

  • secretresolver unit tests:
    • GetActionsService against a fake client, for a missing GitHub config secret, proxy credential secret, TLS config map and vault proxy credential secret. Each must satisfy errors.Is(err, ErrNotFound), and a Forbidden must not.
    • The vault resolver on a 404, a wrapped 404, a 403 and a network error.
    • As a mutation check, disabling the Kubernetes wrap fails all four missing-dependency cases.
  • AutoscalingRunnerSet envtests:
    • removes the finalizer instead of retrying forever (fails on master)
    • keeps the finalizer when the Actions client fails for any other reason
    • deletion with vaultConfig.proxy after its credential secret is gone

Local runs:

  • go test ./controllers/actions.github.com/... with envtest 1.37: pass
  • go vet: clean
  • golangci-lint v2.13.2 with the repo config: 0 new issues

…s gone

deleteRunnerScaleSet returned the GetActionsService error when the
githubConfigSecret no longer existed, so the finalizer was never removed
and the AutoscalingRunnerSet stayed in Terminating forever.

The secret resolver now wraps errors with %w so a NotFound survives the
chain. On NotFound during deletion the controller logs that the scale set
must be removed manually, drops the runner-scale-set-id annotation and
lets the finalizer go. Other errors still requeue.

Fixes actions#4655

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.

Copilot review overview

🟡 Changes recommended

Missing Vault proxy credentials still lose their NotFound error and can leave deletion stuck.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes stuck AutoscalingRunnerSet deletion when required Kubernetes credentials disappear.

Changes:

  • Preserves Kubernetes errors through resolver wrapping.
  • Releases finalizers on dependency NotFound.
  • Adds deletion and retry coverage.
File Description
secretresolver/​secret_resolver.go Preserves underlying resolution errors.
autoscalingrunnerset_controller.go Handles missing client dependencies during deletion.
autoscalingrunnerset_controller_test.go Tests terminal and retryable failures.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

resolverForObject wrapped the ToHTTPProxyConfig error with %v, so a deleted
vault proxy credential secret still left the AutoscalingRunnerSet stuck in
Terminating. Wrap it with %w and cover the path with an envtest.

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.

Copilot review overview

🟢 Approval recommended

The focused deletion fix preserves other error behavior and is adequately covered by integration tests.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

A Kubernetes NotFound only survived for the k8s driver, so an AutoscalingRunnerSet
using Azure Key Vault stayed stuck in Terminating when its secret was deleted.

secretresolver now exports ErrNotFound. The k8s paths (GitHub config secret, proxy
credential secret, vault proxy secret, TLS config map) wrap a Kubernetes NotFound
with it, and the vault resolver wraps an Azure Key Vault 404 (azcore.ResponseError).
Other vault errors keep their previous message only, as before. Deletion checks
errors.Is(err, secretresolver.ErrNotFound) instead of kerrors.IsNotFound.

Signed-off-by: Ankit Jha <[email protected]>

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.

Copilot review overview

🟡 Changes recommended

The deletion diagnostic incorrectly identifies Azure Key Vault failures as missing Kubernetes resources.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)

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.

Copilot review overview

🟢 Approval recommended

The error handling is correctly scoped, preserves retry behavior for non-not-found failures, and has appropriate coverage.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

// wrapVaultNotFound tags an Azure Key Vault 404; other vault errors keep their previous message only.
func wrapVaultNotFound(err error) error {
var responseErr *azcore.ResponseError
if errors.As(err, &responseErr) && responseErr.StatusCode == http.StatusNotFound {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if errors.As(err, &responseErr) && responseErr.StatusCode == http.StatusNotFound {
if errors.As(err, &responseErr) && responseErr.StatusCode == http.StatusNotFound && responseErr.ErrorCode == "SecretNotFound" {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in 0918b6f, thanks. A 404 without SecretNotFound (for example a missing vault) now requeues too, and there is a test case for it.

const ErrNotFound = secretResolverError("not found")

// wrapK8sNotFound tags a Kubernetes NotFound so callers need no knowledge of the driver.
func wrapK8sNotFound(err error) error {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd rename this to wrapKubernetesError(err error)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed in 0918b6f.

}

// wrapVaultNotFound tags an Azure Key Vault 404; other vault errors keep their previous message only.
func wrapVaultNotFound(err error) error {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd rename this to: wrapAzureKeyVaultError
If in the future another vault provider is configured, this implementation would not be valid, but the name is generic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed in 0918b6f. Agreed, the name should say it only understands Azure Key Vault errors.

… vault errors unchanged

GetActionsService is tested against a fake client for a missing GitHub config
secret, proxy credential secret, TLS config map and vault proxy credential
secret, and a Forbidden read must not count as not found. wrapVaultNotFound
now returns non-404 errors as they are instead of re-formatting them.

Signed-off-by: Ankit Jha <[email protected]>

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.

Copilot review overview

🔵 Needs a closer look

Releasing the finalizer without remote deregistration can leave a scale set requiring manual cleanup, so the operational trade-off needs human sign-off.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)

Expect(k8sClient.Delete(ctx, autoscalingRunnerSet)).To(Succeed(), "failed to delete AutoScalingRunnerSet")

Eventually(
arsGone,

@nikola-jokic nikola-jokic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thank you!

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.

AutoscalingRunnerSet deletion wedges forever when githubConfigSecret is gone

3 participants