Skip to content

Commit 33b7bfe

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

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
@@ -614,6 +614,12 @@ func (r *RKE2ControlPlaneReconciler) reconcileDelete(ctx context.Context,
614614

615615
controllerutil.RemoveFinalizer(rcp, controlplanev1.RKE2ControlPlaneFinalizer)
616616

617+
conditions.Set(rcp, metav1.Condition{
618+
Type: controlplanev1.RKE2ControlPlaneDeletingCondition,
619+
Status: metav1.ConditionTrue,
620+
Reason: controlplanev1.RKE2ControlPlaneDeletingDeletionCompletedReason,
621+
})
622+
617623
return ctrl.Result{}, nil
618624
}
619625

@@ -649,6 +655,13 @@ func (r *RKE2ControlPlaneReconciler) reconcileDelete(ctx context.Context,
649655
clusterv1.ConditionSeverityInfo,
650656
"Waiting for worker nodes to be deleted first")
651657

658+
conditions.Set(rcp, metav1.Condition{
659+
Type: controlplanev1.RKE2ControlPlaneDeletingCondition,
660+
Status: metav1.ConditionTrue,
661+
Reason: controlplanev1.RKE2ControlPlaneDeletingWaitingForWorkersDeletionReason,
662+
Message: "Waiting for worker nodes to be deleted first",
663+
})
664+
652665
return ctrl.Result{RequeueAfter: deleteRequeueAfter}, nil
653666
}
654667

@@ -702,6 +715,13 @@ func (r *RKE2ControlPlaneReconciler) reconcileDelete(ctx context.Context,
702715

703716
v1beta1conditions.MarkFalse(rcp, controlplanev1.ResizedV1Beta1Condition, clusterv1.DeletingV1Beta1Reason, clusterv1.ConditionSeverityInfo, "")
704717

718+
conditions.Set(rcp, metav1.Condition{
719+
Type: controlplanev1.RKE2ControlPlaneDeletingCondition,
720+
Status: metav1.ConditionTrue,
721+
Reason: controlplanev1.RKE2ControlPlaneDeletingWaitingForMachineDeletionReason,
722+
Message: "Waiting for control plane Machines to be deleted",
723+
})
724+
705725
return ctrl.Result{RequeueAfter: deleteRequeueAfter}, nil
706726
}
707727

@@ -775,6 +795,11 @@ func (r *RKE2ControlPlaneReconciler) reconcileControlPlaneConditions(
775795
) (res ctrl.Result, retErr error) {
776796
logger := log.FromContext(ctx)
777797

798+
// If the control plane is being deleted, we don't need to reconcile conditions. The DeletingCondition is set directly in reconcileDelete.
799+
if !controlPlane.RCP.DeletionTimestamp.IsZero() {
800+
return ctrl.Result{}, nil
801+
}
802+
778803
// If the cluster is not yet initialized, there is no way to connect to the workload cluster and fetch information
779804
// for updating conditions. Return early.
780805
// We additionally check for the ControlPlaneInitialized condition. The ControlPlaneInitialized condition is set at the same time
@@ -799,7 +824,6 @@ func (r *RKE2ControlPlaneReconciler) reconcileControlPlaneConditions(
799824
readyCPMachines := controlPlane.Machines.Filter(collections.IsReady())
800825

801826
if readyCPMachines.Len() == 0 {
802-
controlPlane.RCP.Status.Initialization.ControlPlaneInitialized = ptr.To(false)
803827
controlPlane.RCP.Status.ReadyReplicas = ptr.To(int32(0))
804828
controlPlane.RCP.Status.AvailableServerIPs = nil
805829

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)