Skip to content

Commit 875cb77

Browse files
committed
KCP: propagate timeouts to Machines with deletionTimestamp
Signed-off-by: Stefan Büringer [email protected]
1 parent d418acf commit 875cb77

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

controlplane/kubeadm/internal/controllers/controller.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,22 @@ func (r *KubeadmControlPlaneReconciler) syncMachines(ctx context.Context, contro
610610
patchHelpers := map[string]*patch.Helper{}
611611
for machineName := range controlPlane.Machines {
612612
m := controlPlane.Machines[machineName]
613-
// If the machine is already being deleted, we don't need to update it.
613+
// If the Machine is already being deleted, we only need to sync
614+
// the subset of fields that impact tearing down the Machine.
614615
if !m.DeletionTimestamp.IsZero() {
616+
patchHelper, err := patch.NewHelper(m, r.Client)
617+
if err != nil {
618+
return err
619+
}
620+
621+
// Set all other in-place mutable fields that impact the ability to tear down existing machines.
622+
m.Spec.NodeDrainTimeout = controlPlane.KCP.Spec.MachineTemplate.NodeDrainTimeout
623+
m.Spec.NodeDeletionTimeout = controlPlane.KCP.Spec.MachineTemplate.NodeDeletionTimeout
624+
m.Spec.NodeVolumeDetachTimeout = controlPlane.KCP.Spec.MachineTemplate.NodeVolumeDetachTimeout
625+
626+
if err := patchHelper.Patch(ctx, m); err != nil {
627+
return err
628+
}
615629
continue
616630
}
617631

controlplane/kubeadm/internal/controllers/controller_test.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,9 @@ func TestKubeadmControlPlaneReconciler_syncMachines(t *testing.T) {
15541554
Bootstrap: clusterv1.Bootstrap{
15551555
DataSecretName: ptr.To("machine-bootstrap-secret"),
15561556
},
1557+
NodeDrainTimeout: duration5s,
1558+
NodeVolumeDetachTimeout: duration5s,
1559+
NodeDeletionTimeout: duration5s,
15571560
},
15581561
}
15591562
g.Expect(env.Create(ctx, deletingMachine, client.FieldOwner(classicManager))).To(Succeed())
@@ -1636,16 +1639,16 @@ func TestKubeadmControlPlaneReconciler_syncMachines(t *testing.T) {
16361639
KCP: kcp,
16371640
Cluster: testCluster,
16381641
Machines: collections.Machines{
1639-
inPlaceMutatingMachine.Name: inPlaceMutatingMachine,
1640-
deletingMachine.Name: deletingMachine,
1641-
nilInfraMachineMachine.Name: nilInfraMachineMachine,
1642+
inPlaceMutatingMachine.Name: inPlaceMutatingMachine.DeepCopy(),
1643+
deletingMachine.Name: deletingMachine.DeepCopy(),
1644+
nilInfraMachineMachine.Name: nilInfraMachineMachine.DeepCopy(),
16421645
},
16431646
KubeadmConfigs: map[string]*bootstrapv1.KubeadmConfig{
1644-
inPlaceMutatingMachine.Name: existingKubeadmConfig,
1647+
inPlaceMutatingMachine.Name: existingKubeadmConfig.DeepCopy(),
16451648
deletingMachine.Name: nil,
16461649
},
16471650
InfraResources: map[string]*unstructured.Unstructured{
1648-
inPlaceMutatingMachine.Name: existingInfraMachine,
1651+
inPlaceMutatingMachine.Name: existingInfraMachine.DeepCopy(),
16491652
deletingMachine.Name: nil,
16501653
},
16511654
}
@@ -1806,7 +1809,14 @@ func TestKubeadmControlPlaneReconciler_syncMachines(t *testing.T) {
18061809
// Verify the machine labels and annotations are unchanged.
18071810
g.Expect(updatedDeletingMachine.Labels).Should(Equal(deletingMachine.Labels))
18081811
g.Expect(updatedDeletingMachine.Annotations).Should(Equal(deletingMachine.Annotations))
1809-
// Verify the machine spec is unchanged.
1812+
// Verify Node timeout values
1813+
g.Expect(updatedDeletingMachine.Spec.NodeDrainTimeout).Should(Equal(kcp.Spec.MachineTemplate.NodeDrainTimeout))
1814+
g.Expect(updatedDeletingMachine.Spec.NodeDeletionTimeout).Should(Equal(kcp.Spec.MachineTemplate.NodeDeletionTimeout))
1815+
g.Expect(updatedDeletingMachine.Spec.NodeVolumeDetachTimeout).Should(Equal(kcp.Spec.MachineTemplate.NodeVolumeDetachTimeout))
1816+
// Verify the machine spec is otherwise unchanged.
1817+
deletingMachine.Spec.NodeDrainTimeout = kcp.Spec.MachineTemplate.NodeDrainTimeout
1818+
deletingMachine.Spec.NodeDeletionTimeout = kcp.Spec.MachineTemplate.NodeDeletionTimeout
1819+
deletingMachine.Spec.NodeVolumeDetachTimeout = kcp.Spec.MachineTemplate.NodeVolumeDetachTimeout
18101820
g.Expect(updatedDeletingMachine.Spec).Should(BeComparableTo(deletingMachine.Spec))
18111821
}
18121822

internal/controllers/machineset/machineset_controller.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -375,18 +375,16 @@ func (r *Reconciler) syncMachines(ctx context.Context, machineSet *clusterv1.Mac
375375
if !m.DeletionTimestamp.IsZero() {
376376
patchHelper, err := patch.NewHelper(m, r.Client)
377377
if err != nil {
378-
return errors.Wrapf(err, "failed to generate patch for Machine %q", klog.KObj(m))
378+
return err
379379
}
380380

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

386-
err = patchHelper.Patch(ctx, m)
387-
if err != nil {
388-
log.Error(err, "Failed to update Machine", "Machine", klog.KObj(m))
389-
return errors.Wrapf(err, "failed to update Machine %q", klog.KObj(m))
386+
if err := patchHelper.Patch(ctx, m); err != nil {
387+
return err
390388
}
391389
continue
392390
}

0 commit comments

Comments
 (0)