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

feat(aws garbage collector) skips snapshots in use #1557

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

jayfranco999
Copy link
Collaborator

Related to jenkins-infra/helpdesk#4355

As per jenkins-infra/helpdesk#4355 (comment)

This PR enables debugging to skip snapshots in use

cleanup/aws_snapshots.sh Outdated Show resolved Hide resolved
@jayfranco999 jayfranco999 changed the title hotfix(aws garbage collector) skips snapshots in use feat(aws garbage collector) skips snapshots in use Nov 28, 2024
@jayfranco999
Copy link
Collaborator Author

jayfranco999 commented Nov 28, 2024

Update:

aws_snapshots.sh now filters the snapshots using ec2 describe-images command and skips the deletion process if used by any instance

Tested locally and successfully:

...
...
== Checking if snapshot snap-0de2d342849db0f36 is in use...
+ aws ec2 describe-images --region=us-east-2 --profile terraform-admin --filters Name=block-device-mapping.snapshot-id,Values=snap-0de2d342849db0f36 --query 'Images[*].ImageId' --output text
+ grep -q .
++ aws ec2 describe-images --region=us-east-2 --profile terraform-admin --filters Name=block-device-mapping.snapshot-id,Values=snap-0de2d342849db0f36 --query 'Images[*].ImageId' --output text
+ ami_ids=ami-08bcac05a9c36fa78
+ echo '[INFO] Snapshot snap-0de2d342849db0f36 is in use by the following AMI(s): ami-08bcac05a9c36fa78. Skipping.'
[INFO] Snapshot snap-0de2d342849db0f36 is in use by the following AMI(s): ami-08bcac05a9c36fa78. Skipping.
+ for snapshot_id in '${snapshot_ids}'
+ echo '== Checking if snapshot snap-02e06c3062de44a91 is in use...'
== Checking if snapshot snap-02e06c3062de44a91 is in use...
+ aws ec2 describe-images --region=us-east-2 --profile terraform-admin --filters Name=block-device-mapping.snapshot-id,Values=snap-02e06c3062de44a91 --query 'Images[*].ImageId' --output text
+ grep -q .
++ aws ec2 describe-images --region=us-east-2 --profile terraform-admin --filters Name=block-device-mapping.snapshot-id,Values=snap-02e06c3062de44a91 --query 'Images[*].ImageId' --output text
+ ami_ids=ami-08fb812ab1ce90606
+ echo '[INFO] Snapshot snap-02e06c3062de44a91 is in use by the following AMI(s): ami-08fb812ab1ce90606. Skipping.'
[INFO] Snapshot snap-02e06c3062de44a91 is in use by the following AMI(s): ami-08fb812ab1ce90606. Skipping.
+ echo '== AWS Packer Cleanup SNAPSHOTS finished.'
== AWS Packer Cleanup SNAPSHOTS finished.

@jayfranco999 jayfranco999 marked this pull request as ready for review November 29, 2024 10:00
@dduportal dduportal merged commit fd8b31a into jenkins-infra:main Nov 29, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants