Skip to content

feat(clusters): delete cluster if secret is deleted (#2060)#2142

Open
jellonek wants to merge 5 commits into
mainfrom
delete-cluster-on-gone-secret
Open

feat(clusters): delete cluster if secret is deleted (#2060)#2142
jellonek wants to merge 5 commits into
mainfrom
delete-cluster-on-gone-secret

Conversation

@jellonek

Copy link
Copy Markdown
Contributor

Description

This PR adds the feature requested in #2060 - cluster resource deletion on secret deletion.

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

Closes #2060

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help
  • Separate ticket for tests # (issue/pr)

Added to documentation?

  • 📜 README.md
  • 🤝 Documentation pages updated
  • 🙅 no documentation needed
  • (if applicable) generated OpenAPI docs for CRD changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

Copilot AI review requested due to automatic review settings July 21, 2026 14:42
@jellonek
jellonek requested review from a team as code owners July 21, 2026 14:42
@github-actions github-actions Bot added size/M documentation Improvements or additions to documentation labels Jul 21, 2026

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.

Pull request overview

Implements automatic Cluster cleanup when the backing Cluster Secret is deleted by extending the cluster bootstrap controller’s Secret deletion handling, and adds test/docs coverage for the offboarding path.

Changes:

  • Trigger Cluster deletion when the controller receives a reconcile request for a missing kubeconfig/OIDC Secret.
  • Add integration/e2e test scenarios covering “secret deleted ⇒ cluster deleted”.
  • Document Secret deletion as an offboarding option.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
internal/controller/cluster/bootstrap_controller.go Deletes the Cluster when its source Secret is missing (e.g., after Secret deletion).
internal/controller/cluster/bootstrap_controller_test.go Adds an envtest case verifying Cluster deletion after Secret deletion.
internal/test/util.go Adds a test helper to reliably delete Secrets in tests.
e2e/cluster/e2e_test.go Adds an e2e scenario validating Cluster deletion after Secret deletion.
docs/user-guides/cluster/offboarding.md Documents Secret deletion as an alternative offboarding trigger.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/controller/cluster/bootstrap_controller.go
Comment thread internal/controller/cluster/bootstrap_controller_test.go Outdated
Comment thread e2e/cluster/e2e_test.go
Comment thread e2e/cluster/e2e_test.go
Comment thread docs/user-guides/cluster/offboarding.md Outdated

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

docs/user-guides/cluster/offboarding.md:40

  • Minor grammar issue: “..., what can be done ...” should be “..., which can be done ...” (or rephrase) to keep the sentence correct and clear.
Another option to trigger `Cluster` off-boarding is manually deleting the cluster `Secret`, what can be done by calling the command:

Comment thread internal/controller/cluster/bootstrap_controller_test.go Outdated
Comment on lines 65 to +69
if err := r.Get(ctx, req.NamespacedName, kubeConfigSecret); err != nil {
if client.IgnoreNotFound(err) == nil {
// missing secret - initiate cluster deletion if it already exists
return ctrl.Result{}, r.requestClusterDeletion(ctx, req.NamespacedName)
}
@jellonek
jellonek force-pushed the delete-cluster-on-gone-secret branch 2 times, most recently from 95a3d96 to d8fd2d5 Compare July 21, 2026 15:28
@github-actions github-actions Bot added size/L and removed size/M labels Jul 22, 2026
@jellonek

Copy link
Copy Markdown
Contributor Author

On hold, as removal of secret is breaking the logic in RemoteClusterReconciler.EnsureDeleted.

@jellonek
jellonek force-pushed the delete-cluster-on-gone-secret branch from cddfab9 to ad3ce10 Compare July 23, 2026 07:42
jellonek added 5 commits July 24, 2026 10:34
Closes #2060

Signed-off-by: Piotr Skamruk <piotr.skamruk@gmail.com>
Signed-off-by: Piotr Skamruk <piotr.skamruk@gmail.com>
Signed-off-by: Piotr Skamruk <piotr.skamruk@gmail.com>
Signed-off-by: Piotr Skamruk <piotr.skamruk@gmail.com>
Signed-off-by: Piotr Skamruk <piotr.skamruk@gmail.com>
@jellonek
jellonek force-pushed the delete-cluster-on-gone-secret branch from 2516b2a to 426ed5d Compare July 24, 2026 08:34
@jellonek

Copy link
Copy Markdown
Contributor Author

Ready for review.

if err := r.Get(ctx, req.NamespacedName, kubeConfigSecret); err != nil {
if client.IgnoreNotFound(err) == nil {
// missing secret - initiate cluster deletion if it already exists
return ctrl.Result{}, r.requestClusterDeletion(ctx, req.NamespacedName)

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.

This won’t work. If secret is missing we cannot clean up helm releases. During bootstrap process please add a finalizer to secret so you can initiate cluster deletion, which in turn will initiate plugins deletion.

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.

ACK.

if client.IgnoreNotFound(err) != nil {
return ctrl.Result{}, lifecycle.Failed, err
}
return ctrl.Result{}, lifecycle.Success, nil

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.

Hmm doesn't lifecycle.Success early-return skips deleteClusterMetrics(cluster) which every other Success path in EnsureDeleted calls?

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.

Yes, it's skipping it, as there is no secret with configuration data needed to make the connection, which is needed to perform that cleanup.
I have added this early return as a best effort to unblock the deletion which without that would be hang in "terminating" state.

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.

Anyway - instead of trying to unblock deletion there - i'll be going into "finalizer on a secret" path suggested by Abhi.

}).Should(Succeed())
})

It("should reconcile the status of a cluster without a secret", func() {

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.

Aren't we loosing coverage here?

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.

We are loosing the coverage for the thing, which is removed by this PR. This whole task is to remove cluster which does not have already "access secret" - without which cluster can not be accessed, so if the cluster has to be removed, there is no way to reconcile its status.

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

Labels

documentation Improvements or additions to documentation size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] - Delete Cluster if Secret is deleted

4 participants