-
Notifications
You must be signed in to change notification settings - Fork 278
✨ Delete router/network/subnet #522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,6 +165,33 @@ INTERFACE_LOOP: | |
return nil | ||
} | ||
|
||
func (s *Service) DeleteRouter(network *infrav1.Network) error { | ||
if network.Router == nil || network.Router.ID == "" { | ||
s.logger.V(4).Info("No need to delete router since no router exists.") | ||
return nil | ||
} | ||
exists, err := s.existsRouter(network.Router.ID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 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 err != nil { | ||
return err | ||
} | ||
if !exists { | ||
s.logger.Info("Skipping router deletion because router doesn't exist", "router", network.Router.ID) | ||
return nil | ||
} | ||
if network.Subnet == nil || network.Subnet.ID == "" { | ||
s.logger.V(4).Info("Skipping removing router interface since no subnet exists.") | ||
} else { | ||
_, 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) | ||
} | ||
return routers.Delete(s.client, network.Router.ID).ExtractErr() | ||
hidekazuna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func (s *Service) getRouterInterfaces(routerID string) ([]ports.Port, error) { | ||
allPages, err := ports.List(s.client, ports.ListOpts{ | ||
DeviceID: routerID, | ||
|
@@ -247,3 +274,17 @@ func GetSubnetsByFilter(networkClient *gophercloud.ServiceClient, opts subnets.L | |
} | ||
return snets, nil | ||
} | ||
|
||
func (s *Service) existsRouter(routerID string) (bool, error) { | ||
if routerID == "" { | ||
return false, nil | ||
} | ||
router, err := routers.Get(s.client, routerID).Extract() | ||
if err != nil { | ||
return false, err | ||
} | ||
if router == nil { | ||
return false, nil | ||
} | ||
return true, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's okay as the cluster network/subnet are afaik always created by us
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I didn't remember clearly, will try this later on and submit PR if need :)