Skip to content

Commit

Permalink
Move deletePorts back to compute package
Browse files Browse the repository at this point in the history
Following up on kubernetes-sigs#950, this moves the deletePorts function back to the
compute package where it can be made a private function.
  • Loading branch information
macaptain authored and pierreprinetti committed Apr 22, 2024
1 parent adb10c5 commit 149d8da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
13 changes: 11 additions & 2 deletions pkg/cloud/services/compute/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (s *Service) createInstance(eventObject runtime.Object, clusterName string,
}

if instanceSpec.Subnet != "" && accessIPv4 == "" {
if err := s.networkingService.DeletePorts(eventObject, portList); err != nil {
if err := s.deletePorts(eventObject, portList); err != nil {
return nil, err
}
return nil, fmt.Errorf("no ports with fixed IPs found on Subnet %q", instanceSpec.Subnet)
Expand Down Expand Up @@ -239,7 +239,7 @@ func (s *Service) createInstance(eventObject runtime.Object, clusterName string,

if mc.ObserveRequest(err) != nil {
serverErr := err
if err = s.networkingService.DeletePorts(eventObject, portList); err != nil {
if err = s.deletePorts(eventObject, portList); err != nil {
return nil, fmt.Errorf("error creating OpenStack instance: %v, error deleting ports: %v", serverErr, err)
}
return nil, fmt.Errorf("error creating Openstack instance: %v", serverErr)
Expand Down Expand Up @@ -442,6 +442,15 @@ func (s *Service) DeleteInstance(eventObject runtime.Object, instance *InstanceS
return s.deleteInstance(eventObject, instanceIdentifier)
}

func (s *Service) deletePorts(eventObject runtime.Object, nets []servers.Network) error {
for _, n := range nets {
if err := s.networkingService.DeletePort(eventObject, n.Port); err != nil {
return err
}
}
return nil
}

func (s *Service) deleteAttachInterface(eventObject runtime.Object, instance *InstanceIdentifier, portID string) error {
mc := metrics.NewMetricPrometheusContext("server_os_interface", "delete")
err := attachinterfaces.Delete(s.computeClient, instance.ID, portID).ExtractErr()
Expand Down
10 changes: 0 additions & 10 deletions pkg/cloud/services/networking/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"time"

"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsbinding"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity"
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
Expand Down Expand Up @@ -225,15 +224,6 @@ func (s *Service) DeletePort(eventObject runtime.Object, portID string) error {
return nil
}

func (s *Service) DeletePorts(eventObject runtime.Object, nets []servers.Network) error {
for _, n := range nets {
if err := s.DeletePort(eventObject, n.Port); err != nil {
return err
}
}
return nil
}

func (s *Service) GarbageCollectErrorInstancesPort(eventObject runtime.Object, instanceName string) error {
portList, err := s.client.ListPort(ports.ListOpts{
Name: instanceName,
Expand Down

0 comments on commit 149d8da

Please sign in to comment.