From 3f434bb70d5982918c029ac835992e09614a1199 Mon Sep 17 00:00:00 2001 From: Mulham Raee Date: Thu, 25 Jan 2024 11:58:04 +0100 Subject: [PATCH] Delay removing the finlaizer until the cluster is fully deleted --- .../controllers/rosacontrolplane_controller.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/controlplane/rosa/controllers/rosacontrolplane_controller.go b/controlplane/rosa/controllers/rosacontrolplane_controller.go index eccf8e6da6..700847215d 100644 --- a/controlplane/rosa/controllers/rosacontrolplane_controller.go +++ b/controlplane/rosa/controllers/rosacontrolplane_controller.go @@ -352,8 +352,7 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc newCluster, err := rosaClient.CreateCluster(clusterSpec) if err != nil { - rosaScope.Info("error", "error", err) - return ctrl.Result{RequeueAfter: 10 * time.Second}, nil + return ctrl.Result{}, fmt.Errorf("failed to create ROSA cluster: %w", err) } rosaScope.Info("cluster created", "state", newCluster.Status().State()) @@ -377,15 +376,22 @@ func (r *ROSAControlPlaneReconciler) reconcileDelete(ctx context.Context, rosaSc return ctrl.Result{}, err } - if cluster != nil { + if cluster == nil { + // cluster is fully deleted, remove finalizer. + controllerutil.RemoveFinalizer(rosaScope.ControlPlane, ROSAControlPlaneFinalizer) + return ctrl.Result{}, nil + } + + if cluster.Status().State() != cmv1.ClusterStateUninstalling { if err := rosaClient.DeleteCluster(cluster.ID()); err != nil { return ctrl.Result{}, err } } - controllerutil.RemoveFinalizer(rosaScope.ControlPlane, ROSAControlPlaneFinalizer) - - return ctrl.Result{}, nil + rosaScope.ControlPlane.Status.Ready = false + rosaScope.Info("waiting for cluster to be deleted") + // Requeue to remove the finalizer when the cluster is fully deleted. + return ctrl.Result{RequeueAfter: time.Second * 60}, nil } func (r *ROSAControlPlaneReconciler) reconcileKubeconfig(ctx context.Context, rosaScope *scope.ROSAControlPlaneScope, rosaClient *rosa.RosaClient, cluster *cmv1.Cluster) error {