feat(clusters): delete cluster if secret is deleted (#2060)#2142
feat(clusters): delete cluster if secret is deleted (#2060)#2142jellonek wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
| 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) | ||
| } |
95a3d96 to
d8fd2d5
Compare
|
On hold, as removal of secret is breaking the logic in |
cddfab9 to
ad3ce10
Compare
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>
2516b2a to
426ed5d
Compare
|
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) |
There was a problem hiding this comment.
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.
| if client.IgnoreNotFound(err) != nil { | ||
| return ctrl.Result{}, lifecycle.Failed, err | ||
| } | ||
| return ctrl.Result{}, lifecycle.Success, nil |
There was a problem hiding this comment.
Hmm doesn't lifecycle.Success early-return skips deleteClusterMetrics(cluster) which every other Success path in EnsureDeleted calls?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
Aren't we loosing coverage here?
There was a problem hiding this comment.
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.
Description
This PR adds the feature requested in #2060 - cluster resource deletion on secret deletion.
What type of PR is this? (check all applicable)
Related Tickets & Documents
Closes #2060
Added tests?
Added to documentation?
Checklist