Skip to content

Commit

Permalink
streamline the vpc cluster deletion process
Browse files Browse the repository at this point in the history
Signed-off-by: Prajyot-Parab <[email protected]>
  • Loading branch information
Prajyot-Parab authored and k8s-infra-cherrypick-robot committed Sep 7, 2023
1 parent f444d3b commit c60e824
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit c60e824

Please sign in to comment.