Skip to content

Commit

Permalink
Fix reconcileDelete machine flow for vpc (#873)
Browse files Browse the repository at this point in the history
Signed-off-by: Prajyot-Parab <[email protected]>

Signed-off-by: Prajyot-Parab <[email protected]>
Co-authored-by: Prajyot-Parab <[email protected]>
  • Loading branch information
1 parent e43256b commit 04c4e7e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ func (m *MachineScope) CreateMachine() (*vpcv1.Instance, error) {

// DeleteMachine deletes the vpc machine associated with machine instance id.
func (m *MachineScope) DeleteMachine() error {
if m.IBMVPCMachine.Status.InstanceID == "" {
return nil
}
options := &vpcv1.DeleteInstanceOptions{}
options.SetID(m.IBMVPCMachine.Status.InstanceID)
_, err := m.IBMVPCClient.DeleteInstance(options)
Expand Down
11 changes: 11 additions & 0 deletions cloud/scope/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ func TestDeleteMachine(t *testing.T) {
setup(t)
t.Cleanup(teardown)
scope := setupMachineScope(clusterName, machineName, mockvpc)
scope.IBMVPCMachine.Status.InstanceID = "foo-instance-id"
mockvpc.EXPECT().DeleteInstance(gomock.AssignableToTypeOf(deleteInstanceOptions)).Return(detailedResponse, nil)
err := scope.DeleteMachine()
g.Expect(err).To(BeNil())
Expand All @@ -283,9 +284,19 @@ func TestDeleteMachine(t *testing.T) {
setup(t)
t.Cleanup(teardown)
scope := setupMachineScope(clusterName, machineName, mockvpc)
scope.IBMVPCMachine.Status.InstanceID = "foo-instance-id"
mockvpc.EXPECT().DeleteInstance(gomock.AssignableToTypeOf(deleteInstanceOptions)).Return(detailedResponse, errors.New("Failed instance deletion"))
err := scope.DeleteMachine()
g.Expect(err).To(Not(BeNil()))
})

t.Run("Empty InstanceID", func(t *testing.T) {
g := NewWithT(t)
setup(t)
t.Cleanup(teardown)
scope := setupMachineScope(clusterName, machineName, mockvpc)
err := scope.DeleteMachine()
g.Expect(err).To(BeNil())
})
})
}

0 comments on commit 04c4e7e

Please sign in to comment.