Skip to content

Commit 38c0b38

Browse files
committed
Fix finalizer calculation in MD/MS controller
Signed-off-by: Stefan Büringer [email protected]
1 parent 2568aa2 commit 38c0b38

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

internal/controllers/machinedeployment/machinedeployment_sync.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,8 @@ func (r *Reconciler) computeDesiredMachineSet(ctx context.Context, deployment *c
257257
name = existingMS.Name
258258
uid = existingMS.UID
259259

260-
// Keep foregroundDeletion finalizer if the existingMS has it.
261-
// Note: This case is a little different from the create case. In the update case we preserve
262-
// the finalizer on the MachineSet if it already exists. Because of SSA we should not build
263-
// the finalizer information from the MachineDeployment when updating a MachineSet because that could lead
264-
// to dropping the finalizer from the MachineSet if it is dropped from the MachineDeployment.
265-
// We should not drop the finalizer on the MachineSet if the finalizer is dropped from the MachineDeployment.
266-
if sets.New[string](existingMS.Finalizers...).Has(metav1.FinalizerDeleteDependents) {
267-
finalizers = []string{metav1.FinalizerDeleteDependents}
268-
}
260+
// Preserve all existing finalizers (including foregroundDeletion finalizer).
261+
finalizers = existingMS.Finalizers
269262

270263
replicas = *existingMS.Spec.Replicas
271264

internal/controllers/machineset/machineset_controller.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3030
"k8s.io/apimachinery/pkg/labels"
3131
kerrors "k8s.io/apimachinery/pkg/util/errors"
32+
"k8s.io/apimachinery/pkg/util/sets"
3233
"k8s.io/apimachinery/pkg/util/wait"
3334
"k8s.io/apiserver/pkg/storage/names"
3435
"k8s.io/client-go/tools/record"
@@ -637,10 +638,18 @@ func (r *Reconciler) computeDesiredMachine(machineSet *clusterv1.MachineSet, exi
637638
if existingMachine != nil {
638639
desiredMachine.SetName(existingMachine.Name)
639640
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+
640650
desiredMachine.Spec.Bootstrap.ConfigRef = existingMachine.Spec.Bootstrap.ConfigRef
641651
desiredMachine.Spec.InfrastructureRef = existingMachine.Spec.InfrastructureRef
642652
}
643-
644653
// Set the in-place mutable fields.
645654
// When we create a new Machine we will just create the Machine with those fields.
646655
// When we update an existing Machine will we update the fields on the existing Machine (in-place mutate).

0 commit comments

Comments
 (0)