mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
AWS: Delete routes during create if they are black-holed
If a route already exists but is invalid (e.g. from a crash), we automatically delete it before trying to create a route that would otherwise conflict.
This commit is contained in:
parent
b494855ebf
commit
7444216d4f
@ -21,6 +21,7 @@ import (
|
|||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/service/ec2"
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
|
"github.com/golang/glog"
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -108,6 +109,32 @@ func (s *AWSCloud) CreateRoute(clusterName string, nameHint string, route *cloud
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var deleteRoute *ec2.Route
|
||||||
|
for _, r := range table.Routes {
|
||||||
|
destinationCIDR := aws.StringValue(r.DestinationCidrBlock)
|
||||||
|
|
||||||
|
if destinationCIDR != route.DestinationCIDR {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if aws.StringValue(r.State) == ec2.RouteStateBlackhole {
|
||||||
|
deleteRoute = r
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if deleteRoute != nil {
|
||||||
|
glog.Infof("deleting blackholed route: %s", aws.StringValue(deleteRoute.DestinationCidrBlock))
|
||||||
|
|
||||||
|
request := &ec2.DeleteRouteInput{}
|
||||||
|
request.DestinationCidrBlock = deleteRoute.DestinationCidrBlock
|
||||||
|
request.RouteTableId = table.RouteTableId
|
||||||
|
|
||||||
|
_, err = s.ec2.DeleteRoute(request)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error deleting blackholed AWS route (%s): %v", deleteRoute.DestinationCidrBlock, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
request := &ec2.CreateRouteInput{}
|
request := &ec2.CreateRouteInput{}
|
||||||
// TODO: use ClientToken for idempotency?
|
// TODO: use ClientToken for idempotency?
|
||||||
request.DestinationCidrBlock = aws.String(route.DestinationCIDR)
|
request.DestinationCidrBlock = aws.String(route.DestinationCIDR)
|
||||||
|
Loading…
Reference in New Issue
Block a user