Skip to content

Commit fac38ac

Browse files
Handle deletion conditions for v1beta2 API
Signed-off-by: Alexandr Demicev <[email protected]>
1 parent ad39e6c commit fac38ac

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

controlplane/internal/controllers/rke2controlplane_controller.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,12 @@ func (r *RKE2ControlPlaneReconciler) reconcileDelete(ctx context.Context,
609609

610610
controllerutil.RemoveFinalizer(rcp, controlplanev1.RKE2ControlPlaneFinalizer)
611611

612+
conditions.Set(rcp, metav1.Condition{
613+
Type: controlplanev1.RKE2ControlPlaneDeletingCondition,
614+
Status: metav1.ConditionTrue,
615+
Reason: controlplanev1.RKE2ControlPlaneDeletingDeletionCompletedReason,
616+
})
617+
612618
return ctrl.Result{}, nil
613619
}
614620

@@ -644,6 +650,13 @@ func (r *RKE2ControlPlaneReconciler) reconcileDelete(ctx context.Context,
644650
clusterv1.ConditionSeverityInfo,
645651
"Waiting for worker nodes to be deleted first")
646652

653+
conditions.Set(rcp, metav1.Condition{
654+
Type: controlplanev1.RKE2ControlPlaneDeletingCondition,
655+
Status: metav1.ConditionTrue,
656+
Reason: controlplanev1.RKE2ControlPlaneDeletingWaitingForWorkersDeletionReason,
657+
Message: "Waiting for worker nodes to be deleted first",
658+
})
659+
647660
return ctrl.Result{RequeueAfter: deleteRequeueAfter}, nil
648661
}
649662

@@ -697,6 +710,13 @@ func (r *RKE2ControlPlaneReconciler) reconcileDelete(ctx context.Context,
697710

698711
v1beta1conditions.MarkFalse(rcp, controlplanev1.ResizedV1Beta1Condition, clusterv1.DeletingV1Beta1Reason, clusterv1.ConditionSeverityInfo, "")
699712

713+
conditions.Set(rcp, metav1.Condition{
714+
Type: controlplanev1.RKE2ControlPlaneDeletingCondition,
715+
Status: metav1.ConditionTrue,
716+
Reason: controlplanev1.RKE2ControlPlaneDeletingWaitingForMachineDeletionReason,
717+
Message: "Waiting for control plane Machines to be deleted",
718+
})
719+
700720
return ctrl.Result{RequeueAfter: deleteRequeueAfter}, nil
701721
}
702722

@@ -770,6 +790,11 @@ func (r *RKE2ControlPlaneReconciler) reconcileControlPlaneConditions(
770790
) (res ctrl.Result, retErr error) {
771791
logger := log.FromContext(ctx)
772792

793+
// If the control plane is being deleted, we don't need to reconcile conditions. The DeletingCondition is set directly in reconcileDelete.
794+
if !controlPlane.RCP.DeletionTimestamp.IsZero() {
795+
return ctrl.Result{}, nil
796+
}
797+
773798
// If the cluster is not yet initialized, there is no way to connect to the workload cluster and fetch information
774799
// for updating conditions. Return early.
775800
// We additionally check for the ControlPlaneInitialized condition. The ControlPlaneInitialized condition is set at the same time
@@ -794,7 +819,6 @@ func (r *RKE2ControlPlaneReconciler) reconcileControlPlaneConditions(
794819
readyCPMachines := controlPlane.Machines.Filter(collections.IsReady())
795820

796821
if readyCPMachines.Len() == 0 {
797-
controlPlane.RCP.Status.Initialization.ControlPlaneInitialized = ptr.To(false)
798822
controlPlane.RCP.Status.ReadyReplicas = ptr.To(int32(0))
799823
controlPlane.RCP.Status.AvailableServerIPs = nil
800824

controlplane/internal/controllers/status.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ func (r *RKE2ControlPlaneReconciler) updateStatus(ctx context.Context, rcp *cont
102102
controlPlane.Cluster, controlPlane.RCP, controlPlane.Machines, controlPlane.InfraMachineTemplateIsNotFound, controlPlane.PreflightCheckResults)
103103
setScalingDownCondition(ctx, controlPlane.Cluster, controlPlane.RCP, controlPlane.Machines, controlPlane.PreflightCheckResults)
104104
setMachinesReadyCondition(ctx, controlPlane.RCP, controlPlane.Machines)
105+
106+
// Return early if the deletion timestamp is set. The DeletingCondition is set directly in reconcileDelete.
107+
if !rcp.DeletionTimestamp.IsZero() {
108+
return nil
109+
}
110+
105111
setDeletingCondition(ctx, controlPlane.RCP, controlPlane.DeletingReason, controlPlane.DeletingMessage)
106112

107113
kubeconfigSecret := corev1.Secret{}

0 commit comments

Comments
 (0)