feat: delete clusters when shoot is deleted (#45)#69
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements cleanup of Greenhouse Cluster resources when the corresponding Gardener Shoot is deleted (404 on previously existing Shoot), and documents the new behavior/events.
Changes:
- Add logic in the Shoot controller to delete an existing Greenhouse
Clusterwhen the Shoot can no longer be fetched due to NotFound. - Emit a new
ClusterDeletedevent and document it in the README. - Add a test intended to validate cluster deletion behavior on Shoot removal.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| README.md | Updates documentation to reflect cluster cleanup behavior and adds the ClusterDeleted event. |
| controller/shoot/shoot_controller.go | Implements deletion of the Greenhouse Cluster when the Shoot is deleted and emits a ClusterDeleted event. |
| controller/shoot/shoot_controller_test.go | Adds a new test case intended to cover Shoot removal leading to Cluster cleanup. |
Comments suppressed due to low confidence (1)
controller/shoot/shoot_controller.go:120
existingClusterFoundis computed incorrectly and will befalseboth when the Cluster exists (err == nil) and when it is NotFound, buttruefor non-NotFound errors. This prevents cluster deletion on Shoot deletion and can also cause an attempted delete of an empty Cluster object when the initial Get fails for transient reasons.
Handle the Cluster Get result explicitly: set existingClusterFound = true only when err == nil, return early on non-NotFound errors, and keep it false on NotFound.
existingClusterFound := false
err := r.GreenhouseClient.Get(ctx, client.ObjectKey{Name: req.Name, Namespace: r.CareInstruction.Namespace}, &existingCluster)
if err == nil {
// Cluster exists - check ownership
if ownerLabel, hasLabel := existingCluster.Labels[v1alpha1.CareInstructionLabel]; hasLabel && ownerLabel != r.CareInstruction.Name {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ab95f25 to
612585f
Compare
| It("should handle shoot removal", func() { | ||
| shoot := &gardenerv1beta1.Shoot{ |
fcd742c to
5ba47dc
Compare
Signed-off-by: Piotr Skamruk <piotr.skamruk@gmail.com>
Merging this branch will decrease overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
Closes #45