-
Notifications
You must be signed in to change notification settings - Fork 1
feat: delete clusters when shoot is deleted (#45) #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
54900e5
feat: delete clusters when shoot is deleted (#45)
jellonek d8a7b1e
fix: address comments from review
jellonek b27cbc9
fix: address comments from review
jellonek 6f5f796
fix: add an event on deletion failure
jellonek d978be0
fix: address comments from review
jellonek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company and Greenhouse contributors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package shoot_test | ||
|
uwe-mayer marked this conversation as resolved.
|
||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
|
|
||
| "shoot-grafter/api/v1alpha1" | ||
| "shoot-grafter/controller/shoot" | ||
| "shoot-grafter/internal/test" | ||
|
|
||
| greenhousev1alpha1 "github.com/cloudoperators/greenhouse/api/v1alpha1" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/interceptor" | ||
| ) | ||
|
|
||
| var _ = Describe("Shoot Controller with fake client", func() { | ||
| AfterEach(func() { | ||
| clusters := &greenhousev1alpha1.ClusterList{} | ||
| Expect(test.K8sClient.List(test.Ctx, clusters, client.InNamespace("default"))).To(Succeed(), "should list Clusters") | ||
| for _, cluster := range clusters.Items { | ||
| Expect(client.IgnoreNotFound(test.K8sClient.Delete(test.Ctx, &cluster))).To(Succeed(), "should delete Cluster resource") | ||
| } | ||
| }) | ||
|
|
||
| When("a shoot controller with fake client is starting", func() { | ||
| BeforeEach(func() { | ||
| careInstruction = &v1alpha1.CareInstruction{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "test-non-happy-path", | ||
| Namespace: "default", | ||
| }, | ||
| } | ||
| }) | ||
| It("should handle shoot removal - non-happy path", func() { | ||
| fakeClient := fake.NewClientBuilder(). | ||
| WithInterceptorFuncs(interceptor.Funcs{ | ||
| Get: func(ctx context.Context, client client.WithWatch, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { | ||
| return errors.New("fake cluster conflict or timeout error") | ||
| }, | ||
| }).Build() | ||
| shootController := shoot.ShootController{ | ||
| GreenhouseClient: test.K8sClient, | ||
| GardenClient: fakeClient, | ||
| Logger: ctrl.Log.WithName("controllers").WithName("ShootController"), | ||
| Name: "ShootController", | ||
| CareInstruction: careInstruction, | ||
| } | ||
|
|
||
| // Simulate the Greenhouse Cluster existing | ||
| cluster := &greenhousev1alpha1.Cluster{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: careInstruction.Name, | ||
| Namespace: careInstruction.Namespace, | ||
| Labels: map[string]string{ | ||
| v1alpha1.CareInstructionLabel: careInstruction.Name, | ||
| }, | ||
| }, | ||
| Spec: greenhousev1alpha1.ClusterSpec{ | ||
| AccessMode: greenhousev1alpha1.ClusterAccessModeDirect, | ||
| }, | ||
| } | ||
| Expect(test.K8sClient.Create(test.Ctx, cluster)).To(Succeed(), "should create Cluster resource") | ||
|
|
||
| req := ctrl.Request{} | ||
| req.Name = cluster.Name | ||
| req.Namespace = cluster.Namespace | ||
| _, err := shootController.Reconcile(test.Ctx, req) | ||
| Expect(err).To(HaveOccurred(), "should fail reconciliation") | ||
|
|
||
| existingCluster := &greenhousev1alpha1.Cluster{} | ||
| Expect(test.K8sClient.Get(test.Ctx, client.ObjectKeyFromObject(cluster), existingCluster)).To(Succeed(), "should keep Cluster resource") | ||
| }) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.