@@ -481,29 +481,30 @@ func (r *ROSAControlPlaneReconciler) deleteMachinePools(ctx context.Context, ros
481481 }
482482
483483 var errs []error
484+ allMachinePoolDeleted := true
484485 for id , mp := range machinePools {
485486 if ! mp .DeletionTimestamp .IsZero () {
486487 continue
487488 }
488489 if err = rosaScope .Client .Delete (ctx , & machinePools [id ]); err != nil {
489490 errs = append (errs , err )
490491 }
491- }
492-
493- // Workaround the case where last machinePool cannot be deleted without deleting the ROSA controlplane.
494- // In Cluster API (CAPI), machine pools (MPs) are normally deleted before the control plane is removed.
495- // However, in ROSA-HCP, deleting the final MP results in an error because the control plane cannot exist without at least 1 MP.
496- // To handle this, when only one MP remains, we ignore the deletion error and proceed with deleting the control plane.
497- // Also OCM cascade delete the MPs when deleting control plane, so we are safe to ignore last MP and delete the control plane.
498- if len (errs ) == 0 && len (machinePools ) == 1 {
499- return true , nil
492+ allMachinePoolDeleted = false
500493 }
501494
502495 if len (errs ) > 0 {
503496 return false , kerrors .NewAggregate (errs )
504497 }
505498
506- return len (machinePools ) == 0 , nil
499+ // Workaround: Handle the dependency issue between MachinePools and the ROSA control plane.
500+ // In Cluster API (CAPI), MachinePools (MPs) are typically deleted before the control plane is deprovisioned.
501+ // However, in ROSA-HCP, a cluster cannot exist without MachinePools, which causes an error when attempting
502+ // to delete them first — preventing the ROSAControlPlane from being removed.
503+ // To resolve this, we initiate the deletion of the MachinePool CRs, wait for one reconcile cycle,
504+ // and then proceed to delete the ROSA-HCP control plane.
505+ // OCM will automatically cascade the deletion of NodePools before the control plane is deleted.
506+
507+ return allMachinePoolDeleted , nil
507508}
508509
509510func (r * ROSAControlPlaneReconciler ) reconcileClusterVersion (rosaScope * scope.ROSAControlPlaneScope , ocmClient rosa.OCMClient , cluster * cmv1.Cluster ) error {
0 commit comments