Skip to content
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

Cleanup EKS VPC peering connections #1173

Merged
merged 2 commits into from
Apr 15, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions hack/aws-acceptance-test-cleanup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,30 @@ func realMain(ctx context.Context) error {

vpcID := cluster.ResourcesVpcConfig.VpcId

filternameAccepter := "accepter-vpc-info.vpc-id"
filternameRequester := "requester-vpc-info.vpc-id"
vpcPeeringConnectionsWithAccepter, err := ec2Client.DescribeVpcPeeringConnections(&ec2.DescribeVpcPeeringConnectionsInput{
Filters: []*ec2.Filter{
{
Name: &filternameAccepter,
Values: []*string{vpcID},
},
},
})

if err != nil {
return err
}
vpcPeeringConnectionsWithRequester, err := ec2Client.DescribeVpcPeeringConnections(&ec2.DescribeVpcPeeringConnectionsInput{
Filters: []*ec2.Filter{
{
Name: &filternameRequester,
Values: []*string{vpcID},
},
},
})
vpcPeeringConnectionsToDelete := append(vpcPeeringConnectionsWithAccepter.VpcPeeringConnections, vpcPeeringConnectionsWithRequester.VpcPeeringConnections...)

// Delete NAT gateways.
natGateways, err := ec2Client.DescribeNatGatewaysWithContext(ctx, &ec2.DescribeNatGatewaysInput{
Filter: []*ec2.Filter{
Expand Down Expand Up @@ -419,6 +443,14 @@ func realMain(ctx context.Context) error {
fmt.Printf("Security group: Destroyed [id=%s]\n", *sg.GroupId)
}

for _, vpcpc := range vpcPeeringConnectionsToDelete {
_, err = ec2Client.DeleteVpcPeeringConnection(&ec2.DeleteVpcPeeringConnectionInput{VpcPeeringConnectionId: vpcpc.VpcPeeringConnectionId})
if err != nil {
return err
}
fmt.Printf("VPC PeeringConnection: Destroyed [id=%s]\n", *vpcpc.VpcPeeringConnectionId)
}

// Delete VPC. Sometimes there's a race condition where AWS thinks
// the VPC still has dependencies but they've already been deleted so
// we may need to retry a couple times.
Expand Down