Skip to content

Add orphaned test-VPC reaper and standardize dry-run across cleaners#2198

Open
sky333999 wants to merge 3 commits into
mainfrom
sky333999/efa-vpc-reaper
Open

Add orphaned test-VPC reaper and standardize dry-run across cleaners#2198
sky333999 wants to merge 3 commits into
mainfrom
sky333999/efa-vpc-reaper

Conversation

@sky333999

Copy link
Copy Markdown
Contributor

Description of changes

clean_eks: after the cluster pass, reap dedicated EFA test VPCs (tag:Name efa-test-vpc-*) left behind by failed terraform destroys. Tears the stack down in dependency order — VPC endpoints, NAT gateways, Elastic IPs, leftover ENIs, internet gateways, subnets, route tables, security groups (revoke-then-delete), then the VPC — behind three safety gates: not backing a live EKS cluster (prod + best-effort beta), no active EC2 instances (re-checked before subnet deletion), and an age gate from the newest NAT gateway/VPC endpoint. A cleaner:reaping tag lets a partially-torn-down VPC resume on a later run instead of being stranded once its age signals are gone.

Shared dry-run: add tool/clean/clean_flags.go (clean.DryRun, RegisterCommonFlags, Skip) and gate every mutating call across all 12 cleaners. Add a -dry-run flag to each tool and a workflow_dispatch dry_run input (DRY_RUN env: scheduled runs stay live, manual defaults to dry-run). Normalize --tags=clean to build-flag position and move ecs/host region args to flag.Arg(0).

Also fix pre-existing bugs surfaced while touching these files:

  • clean_ecs: inverted-sign expiration deleted clusters with active tasks
  • clean_security_group: break-in-select spun pagination to timeout
  • clean_ebs / clean_file_system: age no-op and stale-error under-deletion

License

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Tests

WIP

Requirements

Before commiting your code, please do the following steps.

  1. Run make fmt and make fmt-sh
  2. Run make lint

Integration Tests

To run integration tests against this PR, add the ready for testing label.

clean_eks: after the cluster pass, reap dedicated EFA test VPCs
(tag:Name efa-test-vpc-*) left behind by failed terraform destroys.
Tears the stack down in dependency order — VPC endpoints, NAT gateways,
Elastic IPs, leftover ENIs, internet gateways, subnets, route tables,
security groups (revoke-then-delete), then the VPC — behind three safety
gates: not backing a live EKS cluster (prod + best-effort beta), no
active EC2 instances (re-checked before subnet deletion), and an age
gate from the newest NAT gateway/VPC endpoint. A cleaner:reaping tag lets
a partially-torn-down VPC resume on a later run instead of being stranded
once its age signals are gone.

Shared dry-run: add tool/clean/clean_flags.go (clean.DryRun,
RegisterCommonFlags, Skip) and gate every mutating call across all 12
cleaners. Add a -dry-run flag to each tool and a workflow_dispatch
dry_run input (DRY_RUN env: scheduled runs stay live, manual defaults to
dry-run). Normalize --tags=clean to build-flag position and move
ecs/host region args to flag.Arg(0).

Also fix pre-existing bugs surfaced while touching these files:
- clean_ecs: inverted-sign expiration deleted clusters with active tasks
- clean_security_group: break-in-select spun pagination to timeout
- clean_ebs / clean_file_system: age no-op and stale-error under-deletion
@sky333999 sky333999 force-pushed the sky333999/efa-vpc-reaper branch from 6392598 to 9364aea Compare July 12, 2026 23:46
@sky333999 sky333999 marked this pull request as ready for review July 13, 2026 17:05
@sky333999 sky333999 requested a review from a team as a code owner July 13, 2026 17:05
…waits, vet-clean Skip)

- vpcsInUseByClusters: treat ResourceNotFoundException (a cluster mid-deletion,
  e.g. by terminateClusters just before) as not-in-use and continue, instead of
  aborting the entire VPC reap pass; other errors still fail closed.
- waitVpcEndpointsGone / waitNatGatewaysGone: honor ctx cancellation during the
  poll interval instead of an unconditional time.Sleep.
- clean.Skip: forward the format string so go vet recognizes it as a printf
  wrapper and validates format/arg mismatches at every call site.
- Rename exported ClustersToClean to clustersToClean (package main, no external
  consumers).
- Workflow: quote -dry-run="${DRY_RUN}" and correct the DRY_RUN comment.
- Note the single-Describe-page assumption on the per-VPC delete helpers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant