-
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 { | ||
|
||
| 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") { | ||
|
||
| 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 | ||
|
||
| 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) | ||
|
||
| 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?