Skip to content

Commit a384137

Browse files
authored
Merge pull request #1818 from dulek/skip-port-delete-no-port
🐛 fix: skip port deletion when instances have no port
2 parents 5e82438 + 626c359 commit a384137

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pkg/cloud/services/networking/port.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ func (s *Service) GarbageCollectErrorInstancesPort(eventObject runtime.Object, i
315315
return fmt.Errorf("garbage collection of port %s failed, found %d ports with the same name", portName, len(portList))
316316
}
317317

318+
if len(portList) == 0 {
319+
continue
320+
}
321+
318322
if err := s.DeletePort(eventObject, portList[0].ID); err != nil {
319323
return err
320324
}

pkg/cloud/services/networking/port_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,19 @@ func Test_GarbageCollectErrorInstancesPort(t *testing.T) {
588588
{},
589589
},
590590
wantErr: false,
591+
}, {
592+
name: "garbage collects no ports in an instance",
593+
expect: func(m *mock.MockNetworkClientMockRecorder) {
594+
o1 := ports.ListOpts{
595+
Name: portName1,
596+
}
597+
p1 := []ports.Port{}
598+
m.ListPort(o1).Return(p1, nil)
599+
},
600+
portOpts: []infrav1.PortOpts{
601+
{},
602+
},
603+
wantErr: false,
591604
},
592605
}
593606

0 commit comments

Comments
 (0)