Skip to content

🌱 Propagate timeout fields from MachineSet to Machine during Machine deletion #10589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion internal/controllers/machineset/machineset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,24 @@ func (r *Reconciler) syncMachines(ctx context.Context, machineSet *clusterv1.Mac
log := ctrl.LoggerFrom(ctx)
for i := range machines {
m := machines[i]
// If the machine is already being deleted, we don't need to update it.
// If the machine is already being deleted, we only need to sync
// the subset of fields that impact tearing down a machine
if !m.DeletionTimestamp.IsZero() {
patchHelper, err := patch.NewHelper(m, r.Client)
if err != nil {
return errors.Wrapf(err, "failed to generate patch for Machine %q", klog.KObj(m))
}

// Set all other in-place mutable fields that impact the ability to tear down existing machines.
m.Spec.NodeDrainTimeout = machineSet.Spec.Template.Spec.NodeDrainTimeout
m.Spec.NodeDeletionTimeout = machineSet.Spec.Template.Spec.NodeDeletionTimeout
m.Spec.NodeVolumeDetachTimeout = machineSet.Spec.Template.Spec.NodeVolumeDetachTimeout

err = patchHelper.Patch(ctx, m)
if err != nil {
log.Error(err, "Failed to update Machine", "Machine", klog.KObj(m))
return errors.Wrapf(err, "failed to update Machine %q", klog.KObj(m))
}
continue
}

Expand Down
23 changes: 23 additions & 0 deletions internal/controllers/machineset/machineset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ func TestMachineSetReconciler_syncMachines(t *testing.T) {
replicas := int32(2)
version := "v1.25.3"
duration10s := &metav1.Duration{Duration: 10 * time.Second}
duration11s := &metav1.Duration{Duration: 11 * time.Second}
ms := &clusterv1.MachineSet{
ObjectMeta: metav1.ObjectMeta{
UID: "abc-123-ms-uid",
Expand Down Expand Up @@ -1347,6 +1348,28 @@ func TestMachineSetReconciler_syncMachines(t *testing.T) {
g.Expect(updatedDeletingMachine.Spec.NodeDeletionTimeout).Should(Equal(deletingMachine.Spec.NodeDeletionTimeout))
g.Expect(updatedDeletingMachine.Spec.NodeVolumeDetachTimeout).Should(Equal(deletingMachine.Spec.NodeVolumeDetachTimeout))
}, 5*time.Second).Should(Succeed())

// Verify in-place mutable fields are updated on the deleting machine
ms.Spec.Template.Spec.NodeDrainTimeout = duration11s
ms.Spec.Template.Spec.NodeDeletionTimeout = duration11s
ms.Spec.Template.Spec.NodeVolumeDetachTimeout = duration11s
g.Expect(reconciler.syncMachines(ctx, ms, []*clusterv1.Machine{updatedInPlaceMutatingMachine, deletingMachine})).To(Succeed())
updatedDeletingMachine := deletingMachine.DeepCopy()

g.Expect(env.GetAPIReader().Get(ctx, client.ObjectKeyFromObject(updatedDeletingMachine), updatedDeletingMachine)).To(Succeed())
// Verify Node timeout values
g.Expect(updatedDeletingMachine.Spec.NodeDrainTimeout).Should(And(
Not(BeNil()),
HaveValue(Equal(*ms.Spec.Template.Spec.NodeDrainTimeout)),
))
g.Expect(updatedDeletingMachine.Spec.NodeDeletionTimeout).Should(And(
Not(BeNil()),
HaveValue(Equal(*ms.Spec.Template.Spec.NodeDeletionTimeout)),
))
g.Expect(updatedDeletingMachine.Spec.NodeVolumeDetachTimeout).Should(And(
Not(BeNil()),
HaveValue(Equal(*ms.Spec.Template.Spec.NodeVolumeDetachTimeout)),
))
}

func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
Expand Down
Loading