mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #62729 from databus23/fix-os-route-deletion
Automatic merge from submit-queue (batch tested with PRs 59879, 62729). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Openstack: fix orphaned route deletion This is a follow-up to #56258 which only got half of the work done. The OpenStack cloud providers DeleteRoute method fails to delete routes when it can’t find the corresponding instance in OpenStack. ```release-note OpenStack cloudprovider: Fix deletion of orphaned routes ```
This commit is contained in:
commit
7ffd171c29
@ -83,9 +83,12 @@ func (r *Routes) ListRoutes(ctx context.Context, clusterName string) ([]*cloudpr
|
||||
var routes []*cloudprovider.Route
|
||||
for _, item := range router.Routes {
|
||||
nodeName, foundNode := nodeNamesByAddr[item.NextHop]
|
||||
if !foundNode {
|
||||
nodeName = types.NodeName(item.NextHop)
|
||||
}
|
||||
route := cloudprovider.Route{
|
||||
Name: item.DestinationCIDR,
|
||||
TargetNode: nodeName, //empty if NextHop is unknown
|
||||
TargetNode: nodeName, //contains the nexthop address if node was not found
|
||||
Blackhole: !foundNode,
|
||||
DestinationCIDR: item.DestinationCIDR,
|
||||
}
|
||||
@ -225,10 +228,16 @@ func (r *Routes) DeleteRoute(ctx context.Context, clusterName string, route *clo
|
||||
|
||||
ip, _, _ := net.ParseCIDR(route.DestinationCIDR)
|
||||
isCIDRv6 := ip.To4() == nil
|
||||
addr, err := getAddressByName(r.compute, route.TargetNode, isCIDRv6)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
var addr string
|
||||
|
||||
// Blackhole routes are orphaned and have no counterpart in OpenStack
|
||||
if !route.Blackhole {
|
||||
var err error
|
||||
addr, err = getAddressByName(r.compute, route.TargetNode, isCIDRv6)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
router, err := routers.Get(r.network, r.opts.RouterID).Extract()
|
||||
@ -239,7 +248,7 @@ func (r *Routes) DeleteRoute(ctx context.Context, clusterName string, route *clo
|
||||
routes := router.Routes
|
||||
index := -1
|
||||
for i, item := range routes {
|
||||
if item.DestinationCIDR == route.DestinationCIDR && item.NextHop == addr {
|
||||
if item.DestinationCIDR == route.DestinationCIDR && (item.NextHop == addr || route.Blackhole && item.NextHop == string(route.TargetNode)) {
|
||||
index = i
|
||||
break
|
||||
}
|
||||
@ -255,7 +264,8 @@ func (r *Routes) DeleteRoute(ctx context.Context, clusterName string, route *clo
|
||||
routes = routes[:len(routes)-1]
|
||||
|
||||
unwind, err := updateRoutes(r.network, router, routes)
|
||||
if err != nil {
|
||||
// If this was a blackhole route we are done, there are no ports to update
|
||||
if err != nil || route.Blackhole {
|
||||
return err
|
||||
}
|
||||
defer onFailure.call(unwind)
|
||||
|
Loading…
Reference in New Issue
Block a user