Skip to content

Commit

Permalink
Fix private network cleanup. (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Jun 23, 2023
1 parent ebb823e commit d5306b1
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions pkg/controller/infrastructure/actuator_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,21 @@ func (a *actuator) releaseNetworkResources(d *networkDeleter) error {

nodeCIDR, err := helper.GetNodeCIDR(d.infrastructure, d.cluster)
if err != nil {
privateNetworks, err := metalclient.GetPrivateNetworksFromNodeNetwork(d.ctx, d.mclient, d.infrastructureConfig.ProjectID, nodeCIDR)
return fmt.Errorf("unable to cleanup private networks as the node cidr is not defined: %w", err)
}

privateNetworks, err := metalclient.GetPrivateNetworksFromNodeNetwork(d.ctx, d.mclient, d.infrastructureConfig.ProjectID, nodeCIDR)
if err != nil {
d.logger.Error(err, "failed to query private network", "infrastructure", d.infrastructure.Name, "nodeCIDR", nodeCIDR)
return err
}

for _, pn := range privateNetworks {
_, err := d.mclient.Network().FreeNetwork(network.NewFreeNetworkParams().WithID(*pn.ID).WithContext(d.ctx), nil)
if err != nil {
d.logger.Error(err, "failed to query private network", "infrastructure", d.infrastructure.Name, "nodeCIDR", nodeCIDR)
d.logger.Error(err, "failed to release private network", "infrastructure", d.infrastructure.Name, "networkID", *pn.ID)
return err
}

for _, pn := range privateNetworks {
_, err := d.mclient.Network().FreeNetwork(network.NewFreeNetworkParams().WithID(*pn.ID).WithContext(d.ctx), nil)
if err != nil {
d.logger.Error(err, "failed to release private network", "infrastructure", d.infrastructure.Name, "networkID", *pn.ID)
return err
}
}
} else {
a.logger.Error(err, "unable to cleanup private networks as the node cidr is not defined")
}

return nil
Expand Down

0 comments on commit d5306b1

Please sign in to comment.