diff --git a/controllers/awscluster_controller.go b/controllers/awscluster_controller.go index 8fa29f610c..a3e0368d03 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()