-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Bug 1916692: OpenStack: Delete leftover LBs when destroying cluster #4563
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 |
|---|---|---|
|
|
@@ -646,6 +646,57 @@ func getRouterByPort(client *gophercloud.ServiceClient, allPorts []ports.Port) ( | |
| return "", nil | ||
| } | ||
|
|
||
| func deleteLeftoverLoadBalancers(opts *clientconfig.ClientOpts, logger logrus.FieldLogger, networkID string) { | ||
| conn, err := clientconfig.NewServiceClient("load-balancer", opts) | ||
| if err != nil { | ||
| // Ignore the error if Octavia is not available for the cloud | ||
| var gerr *gophercloud.ErrEndpointNotFound | ||
| if errors.As(err, &gerr) { | ||
| logger.Debug("Skip load balancer deletion because Octavia endpoint is not found") | ||
| return | ||
| } | ||
| logger.Error(err) | ||
| return | ||
| } | ||
|
|
||
| listOpts := loadbalancers.ListOpts{ | ||
| VipNetworkID: networkID, | ||
| } | ||
| allPages, err := loadbalancers.List(conn, listOpts).AllPages() | ||
| if err != nil { | ||
|
Contributor
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 suggest to handle ErrDefault403 errors separately to prevent situations when a user doesn't have permissions to list load balancers
Member
Author
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. Hmm, this is a pattern we're using all over the place in this file, and if we wanted to treat 403 differently I think we should do it in a separate change.
Contributor
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. |
||
| logger.Error(err) | ||
| return | ||
| } | ||
|
|
||
| allLoadBalancers, err := loadbalancers.ExtractLoadBalancers(allPages) | ||
| if err != nil { | ||
| logger.Error(err) | ||
| return | ||
| } | ||
| deleteOpts := loadbalancers.DeleteOpts{ | ||
| Cascade: true, | ||
| } | ||
| for _, loadbalancer := range allLoadBalancers { | ||
| if !strings.HasPrefix(loadbalancer.Description, "Kubernetes external service") { | ||
|
Contributor
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. perhaps this should rely on Loadbalancer tags rather than text on the description
Member
Author
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. We can't. The in-tree cloud provider doesn't tag the LB resources. |
||
| logger.Debugf("Not deleting LoadBalancer %q with description %q", loadbalancer.ID, loadbalancer.Description) | ||
| continue | ||
| } | ||
| logger.Debugf("Deleting LoadBalancer %q", loadbalancer.ID) | ||
| err = loadbalancers.Delete(conn, loadbalancer.ID, deleteOpts).ExtractErr() | ||
| if err != nil { | ||
| // Ignore the error if the load balancer cannot be found | ||
| var gerr gophercloud.ErrDefault404 | ||
|
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. please compare to the line #660
Contributor
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. Actually this is correct... This is how errors in gophercloud are organized |
||
| if !errors.As(err, &gerr) { | ||
| // This can fail when the load balancer is still in use so return/retry | ||
| logger.Debugf("Deleting load balancer %q failed: %v", loadbalancer.ID, err) | ||
| return | ||
| } | ||
| logger.Debugf("Cannot find load balancer %q. It's probably already been deleted.", loadbalancer.ID) | ||
| } | ||
| } | ||
| return | ||
| } | ||
|
|
||
| func isClusterSubnet(subnets []subnets.Subnet, subnetID string) bool { | ||
| for _, subnet := range subnets { | ||
| if subnet.ID == subnetID { | ||
|
|
@@ -731,6 +782,8 @@ func deleteNetworks(opts *clientconfig.ClientOpts, filter Filter, logger logrus. | |
| if !errors.As(err, &gerr) { | ||
| // This can fail when network is still in use | ||
| logger.Debugf("Deleting Network %q failed: %v", network.ID, err) | ||
| // Try to delete eventual leftover load balancers | ||
| deleteLeftoverLoadBalancers(opts, logger, network.ID) | ||
|
Contributor
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. deleteLeftoverLoadBalancers returns bool and error. are you going to handle it?
Member
Author
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 wasn't planning to. I don't want to change the return value of IMO, the destroy module needs a good refactoring that I don't want to commit to right now.
Contributor
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 mean you created a new function
Member
Author
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. OK, I changed the signature. PTAL. |
||
| return false, nil | ||
| } | ||
| logger.Debugf("Cannot find network %q. It's probably already been deleted.", network.ID) | ||
|
|
||
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.
here you use it as a pointer type, and below in the similar clause, as a refular type. This doesn't look consistent?