From 7444216d4fd76a4632869e28c9901cf9c9525bec Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Tue, 10 Nov 2015 17:39:00 -0500 Subject: [PATCH] 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. --- pkg/cloudprovider/providers/aws/aws_routes.go | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/cloudprovider/providers/aws/aws_routes.go b/pkg/cloudprovider/providers/aws/aws_routes.go index 42ba025bb71..7564831af51 100644 --- a/pkg/cloudprovider/providers/aws/aws_routes.go +++ b/pkg/cloudprovider/providers/aws/aws_routes.go @@ -21,6 +21,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" + "github.com/golang/glog" "k8s.io/kubernetes/pkg/cloudprovider" ) @@ -108,6 +109,32 @@ func (s *AWSCloud) CreateRoute(clusterName string, nameHint string, route *cloud 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{} // TODO: use ClientToken for idempotency? request.DestinationCidrBlock = aws.String(route.DestinationCIDR)