diff --git a/.gitignore b/.gitignore index ad847e22c..7abbeb352 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ managevm controller_manager mcm.out kubectl +.cache_ggshield # Binary files of MCM ./machine-controller-manager diff --git a/pkg/util/provider/machinecontroller/machine.go b/pkg/util/provider/machinecontroller/machine.go index 77d21e20f..732dddf6d 100644 --- a/pkg/util/provider/machinecontroller/machine.go +++ b/pkg/util/provider/machinecontroller/machine.go @@ -149,6 +149,12 @@ func (c *controller) reconcileClusterMachine(machine *v1alpha1.Machine) (machine }) } + // Add finalizers if not present on machine object + retry, err = c.addMachineFinalizers(machine) + if err != nil { + return retry, err + } + if machine.Status.Node != "" { // If reference to node object exists execute the below retry, err := c.reconcileMachineHealth(machine) @@ -280,15 +286,9 @@ func (c *controller) triggerCreationFlow(createMachineRequest *driver.CreateMach providerID = "" ) - // Add finalizers if not present - retry, err := c.addMachineFinalizers(createMachineRequest.Machine) - if err != nil { - return retry, err - } - // we should avoid mutating Secret, since it goes all the way into the Informer's store secretCopy := createMachineRequest.Secret.DeepCopy() - err = c.addBootstrapTokenToUserData(machine.Name, secretCopy) + err := c.addBootstrapTokenToUserData(machine.Name, secretCopy) if err != nil { return machineutils.ShortRetry, err } diff --git a/pkg/util/provider/machinecontroller/machine_test.go b/pkg/util/provider/machinecontroller/machine_test.go index 5416efab3..137f5de74 100644 --- a/pkg/util/provider/machinecontroller/machine_test.go +++ b/pkg/util/provider/machinecontroller/machine_test.go @@ -438,52 +438,6 @@ var _ = Describe("machine", func() { Expect(actual.Status.CurrentStatus.Phase).To(Equal(data.expect.machine.Status.CurrentStatus.Phase)) }, - Entry("Machine creation in process. Machine finalizers are UPDATED", &data{ - setup: setup{ - secrets: []*corev1.Secret{ - { - ObjectMeta: *newObjectMeta(objMeta, 0), - }, - }, - machineClaasses: []*v1alpha1.MachineClass{ - { - ObjectMeta: *newObjectMeta(objMeta, 0), - SecretRef: newSecretReference(objMeta, 0), - }, - }, - machines: newMachines(1, &v1alpha1.MachineTemplateSpec{ - ObjectMeta: *newObjectMeta(objMeta, 0), - Spec: v1alpha1.MachineSpec{ - Class: v1alpha1.ClassSpec{ - Kind: "MachineClass", - Name: "machine-0", - }, - }, - }, nil, nil, nil, nil, false, metav1.Now()), - }, - action: action{ - machine: "machine-0", - fakeDriver: &driver.FakeDriver{ - VMExists: false, - ProviderID: "fakeID-0", - NodeName: "fakeNode-0", - Err: nil, - }, - }, - expect: expect{ - machine: newMachine(&v1alpha1.MachineTemplateSpec{ - ObjectMeta: *newObjectMeta(objMeta, 0), - Spec: v1alpha1.MachineSpec{ - Class: v1alpha1.ClassSpec{ - Kind: "MachineClass", - Name: "machineClass", - }, - }, - }, nil, nil, nil, nil, true, metav1.Now()), - err: fmt.Errorf("Machine creation in process. Machine finalizers are UPDATED"), - retry: machineutils.ShortRetry, - }, - }), Entry("Machine creation succeeds with object UPDATE", &data{ setup: setup{ secrets: []*corev1.Secret{