@@ -115,7 +115,9 @@ func (r *RKE2ControlPlaneReconciler) reconcilePreDrainHook(ctx context.Context,
115115
116116 deletingMachine := getDeletingMachineWithHook (ctx ,
117117 controlPlane ,
118- controlplanev1 .PreDrainLoadbalancerExclusionAnnotation )
118+ controlplanev1 .PreDrainLoadbalancerExclusionAnnotation ,
119+ clusterv1 .MachineDeletingWaitingForPreDrainHookReason ,
120+ )
119121 if deletingMachine == nil {
120122 log .V (5 ).Info ("Waiting on other machines to be deleted." )
121123
@@ -170,7 +172,9 @@ func (r *RKE2ControlPlaneReconciler) reconcilePreTerminateHook(ctx context.Conte
170172
171173 deletingMachine := getDeletingMachineWithHook (ctx ,
172174 controlPlane ,
173- controlplanev1 .PreTerminateHookCleanupAnnotation )
175+ controlplanev1 .PreTerminateHookCleanupAnnotation ,
176+ clusterv1 .MachineDeletingWaitingForPreTerminateHookReason ,
177+ )
174178 if deletingMachine == nil {
175179 log .V (5 ).Info ("Waiting on other machines to be deleted." )
176180
@@ -307,6 +311,7 @@ func machineHasOtherHooks(machine *clusterv1.Machine, hookPrefix string, hookAnn
307311func getDeletingMachineWithHook (ctx context.Context ,
308312 controlPlane * rke2.ControlPlane ,
309313 hookAnnotation string ,
314+ hookReason string ,
310315) * clusterv1.Machine {
311316 log := ctrl .LoggerFrom (ctx )
312317 // Return early, if there is already a deleting Machine without the hook.
@@ -325,10 +330,7 @@ func getDeletingMachineWithHook(ctx context.Context,
325330
326331 // Return early because the Machine controller is not yet waiting for the hook.
327332 c := conditions .Get (deletingMachine , clusterv1 .MachineDeletingCondition )
328-
329- // Return early because the Machine controller is not yet waiting for the pre-terminate hook.
330- if c == nil || c .Status != metav1 .ConditionTrue ||
331- (c .Reason != clusterv1 .MachineDeletingWaitingForPreTerminateHookReason && c .Reason != clusterv1 .MachineDeletingWaitingForPreDrainHookReason ) {
333+ if c == nil || c .Status != metav1 .ConditionTrue || c .Reason != hookReason {
332334 log .V (5 ).Info ("Machine is not waiting on condition" , "condition" , clusterv1 .MachineDeletingCondition )
333335
334336 return nil
0 commit comments