Skip to content

Commit ada0c5b

Browse files
committed
Fix Port Leaks
When an instance fails to come up, there's a bug where the port doesn't get cleaned up, and eventually you will exhaust your quota. The code does attempt to garbage collect, but I suspect at some point in the past ports were suffixed with an index, but the garbage collection code wasn't made aware of this, so lists nothing. Replace the APi "filtering" that doesn't work with a manual filter that does prefix matching.
1 parent f938384 commit ada0c5b

File tree

1 file changed

+10
-3
lines changed
  • pkg/cloud/services/networking

1 file changed

+10
-3
lines changed

pkg/cloud/services/networking/port.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,20 @@ func (s *Service) DeletePorts(openStackCluster *infrav1.OpenStackCluster) error
290290
}
291291

292292
func (s *Service) GarbageCollectErrorInstancesPort(eventObject runtime.Object, instanceName string) error {
293-
portList, err := s.client.ListPort(ports.ListOpts{
294-
Name: instanceName,
295-
})
293+
// NOTE: when creating an instance, ports are named using getPortName(), which
294+
// features an index, so we must list all ports and delete those that start with
295+
// the instance name. Specifying the name in the list options will only return
296+
// a direct match.
297+
portList, err := s.client.ListPort(ports.ListOpts{})
296298
if err != nil {
297299
return err
298300
}
301+
299302
for _, p := range portList {
303+
if !strings.HasPrefix(p.Name, instanceName) {
304+
continue
305+
}
306+
300307
if err := s.DeletePort(eventObject, p.ID); err != nil {
301308
return err
302309
}

0 commit comments

Comments
 (0)