From c60e824d2d54b78f9938aaf8ba96e9a2be13c27e Mon Sep 17 00:00:00 2001 From: Prajyot-Parab Date: Wed, 6 Sep 2023 23:57:49 +0530 Subject: [PATCH] streamline the vpc cluster deletion process Signed-off-by: Prajyot-Parab --- cloud/scope/cluster.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cloud/scope/cluster.go b/cloud/scope/cluster.go index 5f0b322d9..9cc27b7cd 100644 --- a/cloud/scope/cluster.go +++ b/cloud/scope/cluster.go @@ -131,6 +131,10 @@ func (s *ClusterScope) CreateVPC() (*vpcv1.VPC, error) { // DeleteVPC deletes IBM VPC associated with a VPC id. func (s *ClusterScope) DeleteVPC() error { + if s.IBMVPCCluster.Status.VPC.ID == "" { + return nil + } + deleteVpcOptions := &vpcv1.DeleteVPCOptions{} deleteVpcOptions.SetID(s.IBMVPCCluster.Status.VPC.ID) _, err := s.IBMVPCClient.DeleteVPC(deleteVpcOptions) @@ -267,6 +271,10 @@ func (s *ClusterScope) ensureFIPUnique(fipName string) (*vpcv1.FloatingIP, error // DeleteFloatingIP deletes a Floating IP associated with floating ip id. func (s *ClusterScope) DeleteFloatingIP() error { + if s.IBMVPCCluster.Status.VPCEndpoint.FIPID == nil { + return nil + } + if fipID := *s.IBMVPCCluster.Status.VPCEndpoint.FIPID; fipID != "" { deleteFIPOption := &vpcv1.DeleteFloatingIPOptions{} deleteFIPOption.SetID(fipID) @@ -410,6 +418,10 @@ func (s *ClusterScope) ensureSubnetUnique(subnetName string) (*vpcv1.Subnet, err // DeleteSubnet deletes a subnet associated with subnet id. func (s *ClusterScope) DeleteSubnet() error { + if s.IBMVPCCluster.Status.Subnet.ID == nil { + return nil + } + subnetID := *s.IBMVPCCluster.Status.Subnet.ID // Lists the subnet available and compare before deleting to avoid any failure(404) later @@ -703,6 +715,10 @@ func (s *ClusterScope) SetLoadBalancerID(id *string) { // GetLoadBalancerID will get the id for the load balancer. func (s *ClusterScope) GetLoadBalancerID() string { + if s.IBMVPCCluster.Status.VPCEndpoint.LBID == nil { + return "" + } + return *s.IBMVPCCluster.Status.VPCEndpoint.LBID }