Skip to content

Commit 04c4e7e

Browse files
Fix reconcileDelete machine flow for vpc (#873)
Signed-off-by: Prajyot-Parab <[email protected]> Signed-off-by: Prajyot-Parab <[email protected]> Co-authored-by: Prajyot-Parab <[email protected]>
1 parent e43256b commit 04c4e7e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

cloud/scope/machine.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ func (m *MachineScope) CreateMachine() (*vpcv1.Instance, error) {
168168

169169
// DeleteMachine deletes the vpc machine associated with machine instance id.
170170
func (m *MachineScope) DeleteMachine() error {
171+
if m.IBMVPCMachine.Status.InstanceID == "" {
172+
return nil
173+
}
171174
options := &vpcv1.DeleteInstanceOptions{}
172175
options.SetID(m.IBMVPCMachine.Status.InstanceID)
173176
_, err := m.IBMVPCClient.DeleteInstance(options)

cloud/scope/machine_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ func TestDeleteMachine(t *testing.T) {
273273
setup(t)
274274
t.Cleanup(teardown)
275275
scope := setupMachineScope(clusterName, machineName, mockvpc)
276+
scope.IBMVPCMachine.Status.InstanceID = "foo-instance-id"
276277
mockvpc.EXPECT().DeleteInstance(gomock.AssignableToTypeOf(deleteInstanceOptions)).Return(detailedResponse, nil)
277278
err := scope.DeleteMachine()
278279
g.Expect(err).To(BeNil())
@@ -283,9 +284,19 @@ func TestDeleteMachine(t *testing.T) {
283284
setup(t)
284285
t.Cleanup(teardown)
285286
scope := setupMachineScope(clusterName, machineName, mockvpc)
287+
scope.IBMVPCMachine.Status.InstanceID = "foo-instance-id"
286288
mockvpc.EXPECT().DeleteInstance(gomock.AssignableToTypeOf(deleteInstanceOptions)).Return(detailedResponse, errors.New("Failed instance deletion"))
287289
err := scope.DeleteMachine()
288290
g.Expect(err).To(Not(BeNil()))
289291
})
292+
293+
t.Run("Empty InstanceID", func(t *testing.T) {
294+
g := NewWithT(t)
295+
setup(t)
296+
t.Cleanup(teardown)
297+
scope := setupMachineScope(clusterName, machineName, mockvpc)
298+
err := scope.DeleteMachine()
299+
g.Expect(err).To(BeNil())
300+
})
290301
})
291302
}

0 commit comments

Comments
 (0)