Skip to content

Commit

Permalink
Fixes issue adding on finalizers on existing mach (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
prashanth26 authored May 19, 2021
1 parent 8b6b626 commit 3858fa7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ managevm
controller_manager
mcm.out
kubectl
.cache_ggshield

# Binary files of MCM
./machine-controller-manager
Expand Down
14 changes: 7 additions & 7 deletions pkg/util/provider/machinecontroller/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
46 changes: 0 additions & 46 deletions pkg/util/provider/machinecontroller/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 3858fa7

Please sign in to comment.