@@ -531,6 +531,16 @@ func (r *MicroK8sControlPlaneReconciler) scaleDownControlPlane(ctx context.Conte
531531 for i := len (machines ) - 1 ; i >= 0 ; i -- {
532532 machine = machines [i ]
533533 logger := logger .WithValues ("machineName" , machine .Name )
534+
535+ // do not allow scaling down until all nodes have nodeRefs
536+ // NOTE(hue): this might happen when we're trying to delete a machine instance that CAN NOT
537+ // get a nodeRef, e.g. because the infra provider is not able to create the machine.
538+ // In this case, requeueing here will not solve the issue and only prevents the machine from being deleted.
539+ if machine .Status .NodeRef == nil {
540+ logger .Info ("machine does not have a nodeRef yet" )
541+ return ctrl.Result {RequeueAfter : 10 * time .Second }, nil
542+ }
543+
534544 if ! machine .ObjectMeta .DeletionTimestamp .IsZero () {
535545 logger .Info ("machine is in process of deletion" )
536546
@@ -555,12 +565,6 @@ func (r *MicroK8sControlPlaneReconciler) scaleDownControlPlane(ctx context.Conte
555565 return ctrl.Result {RequeueAfter : 20 * time .Second }, nil
556566 }
557567
558- // do not allow scaling down until all nodes have nodeRefs
559- if machine .Status .NodeRef == nil {
560- logger .Info ("one of machines does not have NodeRef" )
561- return ctrl.Result {RequeueAfter : 10 * time .Second }, nil
562- }
563-
564568 // mark the oldest machine to be deleted first
565569 if machine .CreationTimestamp .Before (& deleteMachine .CreationTimestamp ) {
566570 deleteMachine = machine
0 commit comments