From fb5674f7158079e9cbf77902aa9916354de53d7c Mon Sep 17 00:00:00 2001 From: Andreas Sommer Date: Thu, 11 Jan 2024 16:00:16 +0100 Subject: [PATCH] Skip AWSCluster deletion reconciliation once CAPA finalizer is gone --- controllers/awscluster_controller.go | 5 +++++ controllers/awscluster_controller_test.go | 1 + controllers/awscluster_controller_unit_test.go | 1 + 3 files changed, 7 insertions(+) diff --git a/controllers/awscluster_controller.go b/controllers/awscluster_controller.go index 49de7add0a..71a1ea1486 100644 --- a/controllers/awscluster_controller.go +++ b/controllers/awscluster_controller.go @@ -200,6 +200,11 @@ func (r *AWSClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) } func (r *AWSClusterReconciler) reconcileDelete(ctx context.Context, clusterScope *scope.ClusterScope) error { + if !controllerutil.ContainsFinalizer(clusterScope.AWSCluster, infrav1.ClusterFinalizer) { + clusterScope.Info("No finalizer on AWSCluster, skipping deletion reconciliation") + return nil + } + clusterScope.Info("Reconciling AWSCluster delete") ec2svc := r.getEC2Service(clusterScope) diff --git a/controllers/awscluster_controller_test.go b/controllers/awscluster_controller_test.go index 1ab83dfd8a..274f623b5f 100644 --- a/controllers/awscluster_controller_test.go +++ b/controllers/awscluster_controller_test.go @@ -374,6 +374,7 @@ func TestAWSClusterReconcilerIntegrationTests(t *testing.T) { g.Expect(testEnv.Cleanup(ctx, &awsCluster, controllerIdentity, ns)).To(Succeed()) }) + awsCluster.Finalizers = []string{infrav1.ClusterFinalizer} cs, err := getClusterScope(awsCluster) g.Expect(err).To(BeNil()) diff --git a/controllers/awscluster_controller_unit_test.go b/controllers/awscluster_controller_unit_test.go index 07328fe8d4..22e3af6ad3 100644 --- a/controllers/awscluster_controller_unit_test.go +++ b/controllers/awscluster_controller_unit_test.go @@ -401,6 +401,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) { t.Run("Should successfully delete AWSCluster with Cluster Finalizer removed", func(t *testing.T) { g := NewWithT(t) awsCluster := getAWSCluster("test", "test") + awsCluster.Finalizers = []string{infrav1.ClusterFinalizer} csClient := setup(t, &awsCluster) defer teardown() deleteCluster()