Skip to content

fix: watch Secrets to clear transient APIKey failures#82

Open
thomasmaas wants to merge 2 commits into
mainfrom
fix/apikey-watch-secrets
Open

fix: watch Secrets to clear transient APIKey failures#82
thomasmaas wants to merge 2 commits into
mainfrom
fix/apikey-watch-secrets

Conversation

@thomasmaas

@thomasmaas thomasmaas commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

The APIKey status controller sets SecretNotFound when the referenced Secret doesn't exist yet. But no watched resource changes when the Secret is subsequently created, so the APIKey stays stuck in Failed state permanently.

Adding a Secret watch triggers re-reconciliation when Secrets are created/updated. The existing calculateFailedCondition logic already re-evaluates and clears the failure when the Secret appears — no additional status logic needed.

Changes

  • internal/controller/apikey_status_controller.go: add Watches(&corev1.Secret{}, ...) to SetupWithManager, update RBAC marker to include list;watch
  • No RBAC manifest change needed — apikey_secret_controller already grants list;watch on Secrets

Context

This unblocks kuadrant-console-plugin#541, which reorders APIKey/Secret creation to set ownerReferences for garbage collection. The new create order (APIKey first, then Secret) triggers this bug.

Fixes #78

Summary by CodeRabbit

  • Bug Fixes
    • API key status information now updates automatically when related Kubernetes Secrets change.
    • Added the required read access to monitor Secret updates.

The APIKey status controller sets SecretNotFound when the referenced
Secret does not exist yet. However, no watched resource changes when
the Secret is subsequently created, so the APIKey stays stuck in
Failed state permanently.

Add a Secret watch so creation/updates trigger re-reconciliation.
The existing calculateFailedCondition logic already re-evaluates
and clears the failure when the Secret appears.

Fixes #78

Signed-off-by: Thomas Maas <thomas@webtypes.com>
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@thomasmaas, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 688fc433-a9d9-4452-94af-eb57fdbddbab

📥 Commits

Reviewing files that changed from the base of the PR and between 35ada60 and 63a85b5.

📒 Files selected for processing (1)
  • internal/controller/apikey_status_controller_test.go
📝 Walkthrough

Walkthrough

The APIKey status controller now has permission to read Kubernetes Secrets and watches Secret resources, enqueueing APIKey status reconciliation when Secrets change.

Changes

APIKey Secret reconciliation

Layer / File(s) Summary
Secret watch and permissions
internal/controller/apikey_status_controller.go
RBAC grants get, list, and watch access to Secrets, while SetupWithManager watches Secret resources and maps events to apikey-status reconciliation requests.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A bunny watched the Secrets hop,
And nudged the status wheel to stop
Its stuck and troubled state—
A tiny watch arrived just late,
Now APIKeys can bloom anew!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: watching Secrets to recover APIKey failures.
Linked Issues check ✅ Passed The Secret watch and RBAC update satisfy issue #78 by re-reconciling APIKey status when the missing Secret appears.
Out of Scope Changes check ✅ Passed The changes stay within the stated scope and only add Secret watching plus the required permissions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/apikey-watch-secrets

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Verify that an APIKey in SecretNotFound state recovers when the
referenced Secret is subsequently created. This is the scenario
triggered by the console-plugin's ownerReference flow (PR #541)
where the APIKey is created before its Secret.

Ref #78

Signed-off-by: Thomas Maas <thomas@webtypes.com>
@thomasmaas thomasmaas requested a review from eguzki July 10, 2026 11:46
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.

APIKey stuck in Failed state when secret is created after the APIKey

1 participant