@@ -29,6 +29,7 @@ import (
29
29
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
30
30
"k8s.io/apimachinery/pkg/labels"
31
31
kerrors "k8s.io/apimachinery/pkg/util/errors"
32
+ "k8s.io/apimachinery/pkg/util/sets"
32
33
"k8s.io/apimachinery/pkg/util/wait"
33
34
"k8s.io/apiserver/pkg/storage/names"
34
35
"k8s.io/client-go/tools/record"
@@ -637,10 +638,18 @@ func (r *Reconciler) computeDesiredMachine(machineSet *clusterv1.MachineSet, exi
637
638
if existingMachine != nil {
638
639
desiredMachine .SetName (existingMachine .Name )
639
640
desiredMachine .SetUID (existingMachine .UID )
641
+
642
+ // Preserve all existing finalizers (including foregroundDeletion finalizer).
643
+ finalizers := existingMachine .Finalizers
644
+ // Ensure MachineFinalizer is set.
645
+ if ! sets .New [string ](finalizers ... ).Has (clusterv1 .MachineFinalizer ) {
646
+ finalizers = append (finalizers , clusterv1 .MachineFinalizer )
647
+ }
648
+ desiredMachine .Finalizers = finalizers
649
+
640
650
desiredMachine .Spec .Bootstrap .ConfigRef = existingMachine .Spec .Bootstrap .ConfigRef
641
651
desiredMachine .Spec .InfrastructureRef = existingMachine .Spec .InfrastructureRef
642
652
}
643
-
644
653
// Set the in-place mutable fields.
645
654
// When we create a new Machine we will just create the Machine with those fields.
646
655
// When we update an existing Machine will we update the fields on the existing Machine (in-place mutate).
0 commit comments