From be2f529a29aaf53538778e472934a399fc58664e Mon Sep 17 00:00:00 2001 From: NiniOak Date: Thu, 7 Mar 2024 14:58:50 -0800 Subject: [PATCH 1/2] NET-8391: fix cleanup script --- .github/workflows/nightly-cleanup.yml | 12 ++++++--- hack/aws-acceptance-test-cleanup/main.go | 31 ++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/.github/workflows/nightly-cleanup.yml b/.github/workflows/nightly-cleanup.yml index 83d6688ac5..fe2047fb11 100644 --- a/.github/workflows/nightly-cleanup.yml +++ b/.github/workflows/nightly-cleanup.yml @@ -1,10 +1,14 @@ # Dispatch to the consul-k8s-workflows with a nightly cron name: nightly-cleanup on: - schedule: - # * is a special character in YAML so you have to quote this string - # Run nightly at 12PM UTC/8AM EST/5AM PST - - cron: '0 12 * * *' + push: + branches: + # REMOVE MEEEEE - Testing only + - "NET-8391_fix_eks_cleanup" + # schedule: + # # * is a special character in YAML so you have to quote this string + # # Run nightly at 12PM UTC/8AM EST/5AM PST + # - cron: '0 12 * * *' # these should be the only settings that you will ever need to change env: diff --git a/hack/aws-acceptance-test-cleanup/main.go b/hack/aws-acceptance-test-cleanup/main.go index e4094ec47e..7e934bb1af 100644 --- a/hack/aws-acceptance-test-cleanup/main.go +++ b/hack/aws-acceptance-test-cleanup/main.go @@ -196,7 +196,7 @@ func realMain(ctx context.Context) error { if err != nil { return err } - toDeleteVPCs = append(vpcsOutput.Vpcs) + toDeleteVPCs = append(toDeleteVPCs, vpcsOutput.Vpcs...) nextToken = vpcsOutput.NextToken if nextToken == nil { break @@ -279,7 +279,7 @@ func realMain(ctx context.Context) error { vpcName, _ := vpcNameAndBuildURL(vpc) cluster, ok := toDeleteClusters[vpcName] if !ok { - fmt.Printf("Found no associated EKS cluster for VPC: %s\n", vpcName) + fmt.Printf("Found no associated EKS cluster for VPC: %s\n", *vpc.VpcId) } else { // Delete node groups. nodeGroups, err := eksClient.ListNodegroupsWithContext(ctx, &eks.ListNodegroupsInput{ @@ -366,6 +366,11 @@ func realMain(ctx context.Context) error { }, }, }) + + if err != nil { + return err + } + vpcPeeringConnectionsToDelete := append(vpcPeeringConnectionsWithAcceptor.VpcPeeringConnections, vpcPeeringConnectionsWithRequester.VpcPeeringConnections...) // Delete NAT gateways. @@ -377,9 +382,11 @@ func realMain(ctx context.Context) error { }, }, }) + if err != nil { return err } + for _, gateway := range natGateways.NatGateways { fmt.Printf("NAT gateway: Destroying... [id=%s]\n", *gateway.NatGatewayId) _, err = ec2Client.DeleteNatGatewayWithContext(ctx, &ec2.DeleteNatGatewayInput{ @@ -484,6 +491,11 @@ func realMain(ctx context.Context) error { }, }, }) + + if err != nil { + return err + } + for _, igw := range igws.InternetGateways { fmt.Printf("Internet gateway: Detaching from VPC... [id=%s]\n", *igw.InternetGatewayId) if err := destroyBackoff(ctx, "Internet Gateway", *igw.InternetGatewayId, func() error { @@ -520,6 +532,11 @@ func realMain(ctx context.Context) error { }, }, }) + + if err != nil { + return err + } + for _, subnet := range subnets.Subnets { fmt.Printf("Subnet: Destroying... [id=%s]\n", *subnet.SubnetId) if err := destroyBackoff(ctx, "Subnet", *subnet.SubnetId, func() error { @@ -547,6 +564,11 @@ func realMain(ctx context.Context) error { }, }, }) + + if err != nil { + return err + } + for _, routeTable := range routeTables.RouteTables { // Find out if this is the main route table. var mainRouteTable bool @@ -580,6 +602,11 @@ func realMain(ctx context.Context) error { }, }, }) + + if err != nil { + return err + } + for _, sg := range sgs.SecurityGroups { if len(sg.IpPermissions) > 0 { revokeSGInput := &ec2.RevokeSecurityGroupIngressInput{GroupId: sg.GroupId} From 8607b3d4370dedcd57d26e2c027b7e241511d5fa Mon Sep 17 00:00:00 2001 From: NiniOak Date: Fri, 8 Mar 2024 10:57:43 -0800 Subject: [PATCH 2/2] cleanup testing comments --- .github/workflows/nightly-cleanup.yml | 12 ++++-------- hack/aws-acceptance-test-cleanup/main.go | 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/nightly-cleanup.yml b/.github/workflows/nightly-cleanup.yml index fe2047fb11..83d6688ac5 100644 --- a/.github/workflows/nightly-cleanup.yml +++ b/.github/workflows/nightly-cleanup.yml @@ -1,14 +1,10 @@ # Dispatch to the consul-k8s-workflows with a nightly cron name: nightly-cleanup on: - push: - branches: - # REMOVE MEEEEE - Testing only - - "NET-8391_fix_eks_cleanup" - # schedule: - # # * is a special character in YAML so you have to quote this string - # # Run nightly at 12PM UTC/8AM EST/5AM PST - # - cron: '0 12 * * *' + schedule: + # * is a special character in YAML so you have to quote this string + # Run nightly at 12PM UTC/8AM EST/5AM PST + - cron: '0 12 * * *' # these should be the only settings that you will ever need to change env: diff --git a/hack/aws-acceptance-test-cleanup/main.go b/hack/aws-acceptance-test-cleanup/main.go index 7e934bb1af..c708940104 100644 --- a/hack/aws-acceptance-test-cleanup/main.go +++ b/hack/aws-acceptance-test-cleanup/main.go @@ -279,7 +279,7 @@ func realMain(ctx context.Context) error { vpcName, _ := vpcNameAndBuildURL(vpc) cluster, ok := toDeleteClusters[vpcName] if !ok { - fmt.Printf("Found no associated EKS cluster for VPC: %s\n", *vpc.VpcId) + fmt.Printf("Found no associated EKS cluster for VPC: %s\n", vpcName) } else { // Delete node groups. nodeGroups, err := eksClient.ListNodegroupsWithContext(ctx, &eks.ListNodegroupsInput{ @@ -382,7 +382,7 @@ func realMain(ctx context.Context) error { }, }, }) - + if err != nil { return err } @@ -495,7 +495,7 @@ func realMain(ctx context.Context) error { if err != nil { return err } - + for _, igw := range igws.InternetGateways { fmt.Printf("Internet gateway: Detaching from VPC... [id=%s]\n", *igw.InternetGatewayId) if err := destroyBackoff(ctx, "Internet Gateway", *igw.InternetGatewayId, func() error {