Skip to content

Commit 218546b

Browse files
authored
Merge pull request #13007 from fabriziopandini/defer-in-place-for-machines-not-yet-provisioned
🌱 Defer in-place updates for machines not yet provisioned
2 parents 608b533 + a23142b commit 218546b

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

internal/controllers/machine/machine_controller_inplace_update.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ func (r *Reconciler) reconcileInPlaceUpdate(ctx context.Context, s *scope) (ctrl
7979
return ctrl.Result{}, nil
8080
}
8181

82+
if !s.machine.Status.NodeRef.IsDefined() {
83+
log.V(5).Info("Machine status.nodeRef is not yet set, skipping in-place update")
84+
return ctrl.Result{}, nil
85+
}
86+
8287
if s.infraMachine == nil {
8388
s.updatingReason = clusterv1.MachineInPlaceUpdateFailedReason
8489
s.updatingMessage = "In-place update not possible: InfraMachine not found"

internal/controllers/machine/machine_controller_inplace_update_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func TestReconcileInPlaceUpdate(t *testing.T) {
130130
machine.Annotations[runtimev1.PendingHooksAnnotation] = runtimecatalog.HookName(runtimehooksv1.UpdateMachine)
131131
machine.Status.Initialization.InfrastructureProvisioned = ptr.To(true)
132132
machine.Status.Initialization.BootstrapDataSecretCreated = ptr.To(true)
133+
machine.Status.NodeRef = clusterv1.MachineNodeReference{Name: "foo"}
133134
return &Reconciler{}, &scope{machine: machine}
134135
},
135136
wantResult: ctrl.Result{},
@@ -181,6 +182,7 @@ func TestReconcileInPlaceUpdate(t *testing.T) {
181182
machine.Annotations[runtimev1.PendingHooksAnnotation] = runtimecatalog.HookName(runtimehooksv1.UpdateMachine)
182183
machine.Status.Initialization.InfrastructureProvisioned = ptr.To(true)
183184
machine.Status.Initialization.BootstrapDataSecretCreated = ptr.To(true)
185+
machine.Status.NodeRef = clusterv1.MachineNodeReference{Name: "foo"}
184186

185187
infra := newTestUnstructured("GenericInfrastructureMachine", "infrastructure.cluster.x-k8s.io/v1beta2", "infra")
186188
infra.SetAnnotations(map[string]string{clusterv1.UpdateInProgressAnnotation: ""})
@@ -242,6 +244,7 @@ func TestReconcileInPlaceUpdate(t *testing.T) {
242244
machine.Annotations[runtimev1.PendingHooksAnnotation] = runtimecatalog.HookName(runtimehooksv1.UpdateMachine)
243245
machine.Status.Initialization.InfrastructureProvisioned = ptr.To(true)
244246
machine.Status.Initialization.BootstrapDataSecretCreated = ptr.To(true)
247+
machine.Status.NodeRef = clusterv1.MachineNodeReference{Name: "foo"}
245248

246249
infra := newTestUnstructured("GenericInfrastructureMachine", "infrastructure.cluster.x-k8s.io/v1beta2", "infra")
247250
infra.SetAnnotations(map[string]string{clusterv1.UpdateInProgressAnnotation: ""})

internal/controllers/machineset/machineset_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,11 @@ func (r *Reconciler) startMoveMachines(ctx context.Context, s *scope, targetMSNa
10001000
continue
10011001
}
10021002

1003+
// Make sure we are not moving machines not yet provisioned.
1004+
if !machine.Status.NodeRef.IsDefined() {
1005+
continue
1006+
}
1007+
10031008
// Note. Machines with the DeleteMachineAnnotation are going to be moved and the new MS
10041009
// will take care of fulfilling this intent as soon as it scales down.
10051010
// Note. Also Machines marked as unhealthy by MHC are going to be moved, because otherwise

internal/controllers/machineset/machineset_controller_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,6 +3012,27 @@ func TestMachineSetReconciler_startMoveMachines(t *testing.T) {
30123012
wantMovedMachines: []string{"m3", "m4"}, // newest machines moved first with NewestMachineSetDeletionOrder
30133013
wantErr: false,
30143014
},
3015+
{
3016+
name: "should not move machines not yet provisioned",
3017+
ms: newMachineSet("ms1", "cluster1", 2,
3018+
withDeletionOrder(clusterv1.NewestMachineSetDeletionOrder),
3019+
withMachineSetLabels(map[string]string{clusterv1.MachineDeploymentUniqueLabel: "123"}),
3020+
withMachineSetAnnotations(map[string]string{clusterv1.MachineSetMoveMachinesToMachineSetAnnotation: "ms2"}),
3021+
),
3022+
targetMS: newMachineSet("ms2", "cluster1", 2,
3023+
withMachineSetLabels(map[string]string{clusterv1.MachineDeploymentUniqueLabel: "456"}),
3024+
withMachineSetAnnotations(map[string]string{clusterv1.MachineSetReceiveMachinesFromMachineSetsAnnotation: "ms1,ms3"}),
3025+
),
3026+
machines: []*clusterv1.Machine{
3027+
fakeMachine("m1", withOwnerMachineSet("ms1"), withMachineLabels(map[string]string{clusterv1.MachineDeploymentUniqueLabel: "123"}), withMachineFinalizer(), withCreationTimestamp(time.Now().Add(-4*time.Minute))),
3028+
fakeMachine("m2", withOwnerMachineSet("ms1"), withMachineLabels(map[string]string{clusterv1.MachineDeploymentUniqueLabel: "123"}), withMachineFinalizer(), withCreationTimestamp(time.Now().Add(-3*time.Minute))),
3029+
},
3030+
machinesToMove: 2,
3031+
interceptorFuncs: interceptor.Funcs{},
3032+
wantMachinesNotMoved: []string{"m1", "m2"},
3033+
wantMovedMachines: []string{},
3034+
wantErr: false,
3035+
},
30153036
{
30163037
name: "should not move deleting machines, decrease the move count",
30173038
ms: newMachineSet("ms1", "cluster1", 2,

0 commit comments

Comments
 (0)