Skip to content

Commit b69cea4

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 b69cea4

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

internal/controllers/machineset/machineset_controller.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,21 @@ 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+
patch := client.MergeFrom(m.DeepCopy())
369+
370+
// Set all other in-place mutable fields that impact the ability to tear down existing machines.
371+
m.Spec.NodeDrainTimeout = machineSet.Spec.Template.Spec.NodeDrainTimeout
372+
m.Spec.NodeDeletionTimeout = machineSet.Spec.Template.Spec.NodeDeletionTimeout
373+
m.Spec.NodeVolumeDetachTimeout = machineSet.Spec.Template.Spec.NodeVolumeDetachTimeout
374+
375+
err := r.Client.Patch(ctx, m, patch)
376+
if err != nil {
377+
log.Error(err, "Failed to update Machine", "Machine", klog.KObj(m))
378+
return errors.Wrapf(err, "failed to update Machine %q", klog.KObj(m))
379+
}
367380
continue
368381
}
369382

internal/controllers/machineset/machineset_controller_test.go

+25
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,30 @@ 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.Eventually(func(g Gomega) {
1360+
g.Expect(env.GetAPIReader().Get(ctx, client.ObjectKeyFromObject(updatedDeletingMachine), updatedDeletingMachine)).To(Succeed())
1361+
// Verify Node timeout values
1362+
g.Expect(updatedDeletingMachine.Spec.NodeDrainTimeout).Should(And(
1363+
Not(BeNil()),
1364+
HaveValue(Equal(*ms.Spec.Template.Spec.NodeDrainTimeout)),
1365+
))
1366+
g.Expect(updatedDeletingMachine.Spec.NodeDeletionTimeout).Should(And(
1367+
Not(BeNil()),
1368+
HaveValue(Equal(*ms.Spec.Template.Spec.NodeDeletionTimeout)),
1369+
))
1370+
g.Expect(updatedDeletingMachine.Spec.NodeVolumeDetachTimeout).Should(And(
1371+
Not(BeNil()),
1372+
HaveValue(Equal(*ms.Spec.Template.Spec.NodeVolumeDetachTimeout)),
1373+
))
1374+
}, timeout).Should(Succeed())
13501375
}
13511376

13521377
func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {

0 commit comments

Comments
 (0)