Skip to content

Commit 853f4bf

Browse files
committed
Fix delete rosa-hcp
Signed-off-by: serngawy <[email protected]>
1 parent 26bbb03 commit 853f4bf

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

controlplane/rosa/controllers/rosacontrolplane_controller.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

509510
func (r *ROSAControlPlaneReconciler) reconcileClusterVersion(rosaScope *scope.ROSAControlPlaneScope, ocmClient rosa.OCMClient, cluster *cmv1.Cluster) error {

exp/controllers/rosamachinepool_controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ func (r *ROSAMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Requ
131131
controlPlane := &rosacontrolplanev1.ROSAControlPlane{}
132132
if err := r.Client.Get(ctx, controlPlaneKey, controlPlane); err != nil {
133133
if apierrors.IsNotFound(err) && !rosaMachinePool.DeletionTimestamp.IsZero() {
134+
// When the ROSAControlPlane is not found and the ROSAMachinePool CR is marked for deletion,
135+
// it indicates that the ROSAControlPlane (and its associated NodePools) has already been deleted,
136+
// while the ROSAMachinePool remains pending — since a ROSA-HCP cluster cannot exist without a NodePool.
137+
// To handle this scenario, we trigger deletion of the ROSAControlPlane CR to initiate cleanup of the ROSA-HCP,
138+
// relying on OCM to cascade-delete the related NodePools.
139+
// Note: This state should rarely occur. However, during smoke tests, the ROSAMachinePool reconcile cycle
140+
// may occasionally lag behind the deletion of the NodePools and ROSAControlPlane.
134141
log.Info("RosaControlPlane not found, RosaMachinePool is deleted")
135142
patchHelper, err := patch.NewHelper(rosaMachinePool, r.Client)
136143
if err != nil {

0 commit comments

Comments
 (0)