Skip to content

Commit

Permalink
Fix Port Leaks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
spjmurray committed Aug 21, 2023
1 parent f938384 commit ada0c5b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/cloud/services/networking/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,20 @@ func (s *Service) DeletePorts(openStackCluster *infrav1.OpenStackCluster) error
}

func (s *Service) GarbageCollectErrorInstancesPort(eventObject runtime.Object, instanceName string) error {
portList, err := s.client.ListPort(ports.ListOpts{
Name: instanceName,
})
// NOTE: when creating an instance, ports are named using getPortName(), which
// features an index, so we must list all ports and delete those that start with
// the instance name. Specifying the name in the list options will only return
// a direct match.
portList, err := s.client.ListPort(ports.ListOpts{})
if err != nil {
return err
}

for _, p := range portList {
if !strings.HasPrefix(p.Name, instanceName) {
continue
}

if err := s.DeletePort(eventObject, p.ID); err != nil {
return err
}
Expand Down

0 comments on commit ada0c5b

Please sign in to comment.