diff --git a/controllers/awscluster_controller.go b/controllers/awscluster_controller.go index d0ffbbc462..dc28cdaa63 100644 --- a/controllers/awscluster_controller.go +++ b/controllers/awscluster_controller.go @@ -312,6 +312,11 @@ func (r *AWSClusterReconciler) reconcileLoadBalancer(ctx context.Context, cluste } func (r *AWSClusterReconciler) reconcileNormal(ctx context.Context, clusterScope *scope.ClusterScope) (reconcile.Result, error) { + if !clusterScope.Cluster.DeletionTimestamp.IsZero() { + clusterScope.Info("Cluster owning the AWSCluster is being deleted, skipping reconciliation") + return reconcile.Result{}, nil + } + clusterScope.Info("Reconciling AWSCluster") awsCluster := clusterScope.AWSCluster diff --git a/controllers/awscluster_controller_unit_test.go b/controllers/awscluster_controller_unit_test.go index ee2d0bb9cf..973754736c 100644 --- a/controllers/awscluster_controller_unit_test.go +++ b/controllers/awscluster_controller_unit_test.go @@ -72,6 +72,12 @@ func TestAWSClusterReconcilerReconcile(t *testing.T) { ownerCluster: &clusterv1.Cluster{ObjectMeta: metav1.ObjectMeta{GenerateName: "capi-test-"}}, expectError: false, }, + { + name: "Should not Reconcile if owner cluster is deleted", + awsCluster: &infrav1.AWSCluster{ObjectMeta: metav1.ObjectMeta{GenerateName: "aws-test-"}}, + ownerCluster: &clusterv1.Cluster{ObjectMeta: metav1.ObjectMeta{GenerateName: "capi-test-", DeletionTimestamp: &metav1.Time{Time: time.Now()}}}, + expectError: false, + }, { name: "Should Reconcile successfully if no AWSCluster found", expectError: false,