From 149d8da5eaa493da301bd6a03c4dd50e0d3a9948 Mon Sep 17 00:00:00 2001 From: Michael Captain Date: Tue, 21 Sep 2021 17:39:27 +0300 Subject: [PATCH] Move deletePorts back to compute package Following up on #950, this moves the deletePorts function back to the compute package where it can be made a private function. --- pkg/cloud/services/compute/instance.go | 13 +++++++++++-- pkg/cloud/services/networking/port.go | 10 ---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pkg/cloud/services/compute/instance.go b/pkg/cloud/services/compute/instance.go index ebcd69a707..8c243593c8 100644 --- a/pkg/cloud/services/compute/instance.go +++ b/pkg/cloud/services/compute/instance.go @@ -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) @@ -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) @@ -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() diff --git a/pkg/cloud/services/networking/port.go b/pkg/cloud/services/networking/port.go index ad26c93224..83e7e5ca5d 100644 --- a/pkg/cloud/services/networking/port.go +++ b/pkg/cloud/services/networking/port.go @@ -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" @@ -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,