Skip to content

Commit

Permalink
ore/aws/delete-image: Handle missing SnapshotID
Browse files Browse the repository at this point in the history
Added a check for when the snapshotID is None by giving it the value
of detectFromAMI. Then we aim to determine the snapshot by seeing if
we have any associated with the AMI-ID. If nothing shows up, we define
it as pruned
  • Loading branch information
gursewak1997 committed Oct 3, 2024
1 parent 3a76784 commit de10fe1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions mantle/cmd/ore/aws/delete-image.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ func runDeleteImage(cmd *cobra.Command, args []string) {
}

if snapshotID != "" {
if snapshotID == "detectFromAMI" && amiID != "" {
// Let's try to extract the snapshotID from AMI
snapshot, err := API.FindSnapshot(amiID)
if err != nil {
fmt.Fprintf(os.Stderr, "Warning: Encountered error when searching for snapshot for %s: %s. Continuing..\n", amiID, err)
os.Exit(0)
} else if snapshot == nil {
fmt.Fprintf(os.Stdout, "No valid snapshot found for %s.\n", amiID)
os.Exit(0)
}
snapshotID = snapshot.SnapshotID
}
err := API.RemoveBySnapshotTag(snapshotID, allowMissing)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not delete %v: %v\n", snapshotID, err)
Expand Down
4 changes: 3 additions & 1 deletion src/cmd-cloud-prune
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ def deregister_aws_amis(build, cloud_config, dry_run):
for ami in amis:
region_name = ami.get("name")
ami_id = ami.get("hvm")
snapshot_id = ami.get("snapshot")
# If we are dealing with an old manifest where the snapshot ID isn't stored
# then let's instruct ore to detect the snapshot ID from the AMI.
snapshot_id = ami.get("snapshot", "detectFromAMI")
if dry_run:
print(f"Would delete {ami_id} and {snapshot_id} for {build.id}")
continue
Expand Down

0 comments on commit de10fe1

Please sign in to comment.