Skip to content

Commit da2b7c8

Browse files
committed
Propagate values inplace during machine deletion that pertain to machine deletion
Signed-off-by: David Vossel <[email protected]>
1 parent e7c3d5f commit da2b7c8

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

internal/controllers/machineset/machineset_controller.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,24 @@ func (r *Reconciler) syncMachines(ctx context.Context, machineSet *clusterv1.Mac
362362
log := ctrl.LoggerFrom(ctx)
363363
for i := range machines {
364364
m := machines[i]
365-
// If the machine is already being deleted, we don't need to update it.
365+
// If the machine is already being deleted, we only need to sync
366+
// the subset of fields that impact tearing down a machine
366367
if !m.DeletionTimestamp.IsZero() {
368+
patchHelper, err := patch.NewHelper(m, r.Client)
369+
if err != nil {
370+
return errors.Wrapf(err, "failed to generate patch for Machine %q", klog.KObj(m))
371+
}
372+
373+
// Set all other in-place mutable fields that impact the ability to tear down existing machines.
374+
m.Spec.NodeDrainTimeout = machineSet.Spec.Template.Spec.NodeDrainTimeout
375+
m.Spec.NodeDeletionTimeout = machineSet.Spec.Template.Spec.NodeDeletionTimeout
376+
m.Spec.NodeVolumeDetachTimeout = machineSet.Spec.Template.Spec.NodeVolumeDetachTimeout
377+
378+
err = patchHelper.Patch(ctx, m)
379+
if err != nil {
380+
log.Error(err, "Failed to update Machine", "Machine", klog.KObj(m))
381+
return errors.Wrapf(err, "failed to update Machine %q", klog.KObj(m))
382+
}
367383
continue
368384
}
369385

internal/controllers/machineset/machineset_controller_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ func TestMachineSetReconciler_syncMachines(t *testing.T) {
10081008
replicas := int32(2)
10091009
version := "v1.25.3"
10101010
duration10s := &metav1.Duration{Duration: 10 * time.Second}
1011+
duration11s := &metav1.Duration{Duration: 11 * time.Second}
10111012
ms := &clusterv1.MachineSet{
10121013
ObjectMeta: metav1.ObjectMeta{
10131014
UID: "abc-123-ms-uid",
@@ -1347,6 +1348,28 @@ func TestMachineSetReconciler_syncMachines(t *testing.T) {
13471348
g.Expect(updatedDeletingMachine.Spec.NodeDeletionTimeout).Should(Equal(deletingMachine.Spec.NodeDeletionTimeout))
13481349
g.Expect(updatedDeletingMachine.Spec.NodeVolumeDetachTimeout).Should(Equal(deletingMachine.Spec.NodeVolumeDetachTimeout))
13491350
}, 5*time.Second).Should(Succeed())
1351+
1352+
// Verify in-place mutable fields are updated on the deleting machine
1353+
ms.Spec.Template.Spec.NodeDrainTimeout = duration11s
1354+
ms.Spec.Template.Spec.NodeDeletionTimeout = duration11s
1355+
ms.Spec.Template.Spec.NodeVolumeDetachTimeout = duration11s
1356+
g.Expect(reconciler.syncMachines(ctx, ms, []*clusterv1.Machine{updatedInPlaceMutatingMachine, deletingMachine})).To(Succeed())
1357+
updatedDeletingMachine := deletingMachine.DeepCopy()
1358+
1359+
g.Expect(env.GetAPIReader().Get(ctx, client.ObjectKeyFromObject(updatedDeletingMachine), updatedDeletingMachine)).To(Succeed())
1360+
// Verify Node timeout values
1361+
g.Expect(updatedDeletingMachine.Spec.NodeDrainTimeout).Should(And(
1362+
Not(BeNil()),
1363+
HaveValue(Equal(*ms.Spec.Template.Spec.NodeDrainTimeout)),
1364+
))
1365+
g.Expect(updatedDeletingMachine.Spec.NodeDeletionTimeout).Should(And(
1366+
Not(BeNil()),
1367+
HaveValue(Equal(*ms.Spec.Template.Spec.NodeDeletionTimeout)),
1368+
))
1369+
g.Expect(updatedDeletingMachine.Spec.NodeVolumeDetachTimeout).Should(And(
1370+
Not(BeNil()),
1371+
HaveValue(Equal(*ms.Spec.Template.Spec.NodeVolumeDetachTimeout)),
1372+
))
13501373
}
13511374

13521375
func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {

0 commit comments

Comments
 (0)