✨ Delete router/network/subnet#522
Conversation
|
/assign @sbueringer |
|
looks good to me. I'll test it later. Don't we have to delete the subnet? |
|
@sbueringer When we delete a network, The subnet is deleted as well. |
okay thx good to know |
| log.Info("OpenStack router deleted successfully") | ||
| } | ||
|
|
||
| if openStackCluster.Status.Network != nil { |
There was a problem hiding this comment.
I don't remember clearly, do we have a chance that the network/router is not created by CPAO?
others LGTM
There was a problem hiding this comment.
I think it's okay as the cluster network/subnet are afaik always created by us
There was a problem hiding this comment.
ok, I didn't remember clearly, will try this later on and submit PR if need :)
|
@hidekazuna two small nits, apart from that everything worked :) |
62b57e3 to
bf4a6aa
Compare
|
@sbueringer Thanks, fixed. |
bf4a6aa to
0d46dd6
Compare
| if err != nil { | ||
| return err | ||
| } | ||
| if exists { |
There was a problem hiding this comment.
I think a guard close would be more idiomatic in go, i.e.:
if !exist {
s.logger.Info("No router", "router", network.Router.ID)
return nil
}
if network.Subnet == nil || network.Subnet.ID == "" {
s.logger.V(4).Info("No need to remove router interface since no subnet exists.")
return nil
}
_, err := routers.RemoveInterface(s.client, network.Router.ID, routers.RemoveInterfaceOpts{
SubnetID: network.Subnet.ID,
}).Extract()
if err != nil {
return fmt.Errorf("unable to remove router interface: %v", err)
}
s.logger.V(4).Info("Removed RouterInterface of Router", "id", network.Router.ID)
err = routers.Delete(s.client, network.Router.ID).ExtractErr((same for DeleteNetwork)
| } | ||
|
|
||
| func (s *Service) DeleteRouter(network *infrav1.Network) error { | ||
| exists, err := s.existsRouter(network.Router.ID) |
There was a problem hiding this comment.
I think you still have to check for empty routerID as in you're previous commit. The problem is if the ID is an empty string
and you list all routers in existsRouter without an ID you get all existing routers (same for network)
EDIT: Just looked it up. I would suggest using routers.Get (& networks.Get) instead. Should be even save with empty ID and just returns 0 or 1 router not all so should be more efficient. Although I would still check for the empty string before and then checking for the existence with get
| if openStackCluster.Status.Network.Router != nil { | ||
| log.Info("Deleting router", "name", openStackCluster.Status.Network.Router.Name) | ||
| err := networkingService.DeleteRouter(openStackCluster.Status.Network) | ||
| if err != nil { |
There was a problem hiding this comment.
when you're already on it :). You can inline this to
if err := networkingService.DeleteRouter(openStackCluster.Status.Network); err != nil {2b14d1e to
2ca712e
Compare
|
@sbueringer Fixed. |
9d6537a to
31a3e82
Compare
31a3e82 to
4b9c46d
Compare
|
/lgtm |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hidekazuna, sbueringer The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What this PR does / why we need it:
This PR adds to delete router, network, and subnet feature. Currently how to delete cluster is not provided explicitly in my understanding, but we need to delete OpenStack resources easily even for testing. By this PR, we can delete OpenStack resources created with
cluster-template-without-lb.yamlby the following.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #
Special notes for your reviewer:
Release note: