From fef8eee2a82c1521c8cf341558c982163c312987 Mon Sep 17 00:00:00 2001 From: vismishr Date: Wed, 17 Jun 2026 08:26:30 +0530 Subject: [PATCH] fix(aws): retry on InvalidRouteTableId.NotFound during route creation AWS eventual consistency can cause CreateRoute to fail with InvalidRouteTableId.NotFound immediately after CreateRouteTable returns. Add retry with backoff for this error, matching the existing pattern in CreateVPCS3Endpoint. --- cmd/infra/aws/ec2.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/cmd/infra/aws/ec2.go b/cmd/infra/aws/ec2.go index 1c78d68421e7..73eab83b8f51 100644 --- a/cmd/infra/aws/ec2.go +++ b/cmd/infra/aws/ec2.go @@ -466,7 +466,8 @@ func (o *CreateInfraOptions) CreatePrivateRouteTable(ctx context.Context, l logr isRetriable := func(err error) bool { var apiErr smithy.APIError if errors.As(err, &apiErr) { - return strings.EqualFold(apiErr.ErrorCode(), invalidNATGatewayError) + return strings.EqualFold(apiErr.ErrorCode(), invalidNATGatewayError) || + strings.EqualFold(apiErr.ErrorCode(), invalidRouteTableID) } return false } @@ -553,10 +554,20 @@ func (o *CreateInfraOptions) CreatePublicRouteTable(ctx context.Context, l logr. // Create route to internet gateway if !o.hasInternetGatewayRoute(routeTable, igwID) { - _, err = client.CreateRoute(ctx, &ec2.CreateRouteInput{ - DestinationCidrBlock: aws.String("0.0.0.0/0"), - RouteTableId: aws.String(tableID), - GatewayId: aws.String(igwID), + isRetriable := func(err error) bool { + var apiErr smithy.APIError + if errors.As(err, &apiErr) { + return strings.EqualFold(apiErr.ErrorCode(), invalidRouteTableID) + } + return false + } + err = retry.OnError(retryBackoff, isRetriable, func() error { + _, err = client.CreateRoute(ctx, &ec2.CreateRouteInput{ + DestinationCidrBlock: aws.String("0.0.0.0/0"), + RouteTableId: aws.String(tableID), + GatewayId: aws.String(igwID), + }) + return err }) if err != nil { return "", fmt.Errorf("cannot create route to internet gateway: %w", err)