Skip to content

Commit

Permalink
cmd-coreos-prune: Add build pruning after other actions
Browse files Browse the repository at this point in the history
We wanna make every other action is run before we prune a build fully
and delete the s3 dir. It makes sure the meta.json is still available
if needed.
  • Loading branch information
gursewak1997 committed Dec 11, 2024
1 parent d422dc6 commit 831401d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/cmd-coreos-prune
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def main():
builds_json_data = json.load(f)
# Original list of builds
builds = builds_json_data["builds"]
pruned_build_ids = []
builds_to_prune = []
images_to_keep = policy.get(stream, {}).get("images-keep", [])
barrier_releases = set()
# Get the update graph for stable streams
Expand All @@ -137,7 +137,7 @@ def main():
current_build = Build(id=build_id, images=images, arch=arch, meta_json=meta_json)

# Iterate over actions (policy types) to apply pruning
for action in ['cloud-uploads', 'images', 'build', 'containers']:
for action in ['cloud-uploads', 'images', 'containers', 'build']:
if action not in policy[stream]:
continue
action_duration = convert_duration_to_days(policy[stream][action])
Expand Down Expand Up @@ -172,8 +172,7 @@ def main():
prune_images(s3_client, current_build, images_to_keep, args.dry_run, bucket, prefix)
# Fully prune releases that are very old including deleting the directory in s3 for that build.
case "build":
prune_build(s3_client, bucket, prefix, build_id, args.dry_run)
pruned_build_ids.append(build_id)
builds_to_prune.append(build_id)
case "containers":
# Our containers are manifest listed, which means deleting the container tag
# for one architecture deletes it for all of them. We'll choose to only prune
Expand Down Expand Up @@ -202,12 +201,14 @@ def main():
else:
policy_cleanup[action] = True

if pruned_build_ids:
if builds_to_prune:
for build_id in builds_to_prune:
prune_build(s3_client, bucket, prefix, build_id, args.dry_run)
if "tombstone-builds" not in builds_json_data:
builds_json_data["tombstone-builds"] = []
# Separate the builds into remaining builds and tombstone builds
remaining_builds = [build for build in builds if build["id"] not in pruned_build_ids]
tombstone_builds = [build for build in builds if build["id"] in pruned_build_ids]
remaining_builds = [build for build in builds if build["id"] not in builds_to_prune]
tombstone_builds = [build for build in builds if build["id"] in builds_to_prune]
# Update the data structure
builds_json_data["builds"] = remaining_builds
builds_json_data["tombstone-builds"].extend(tombstone_builds)
Expand Down

0 comments on commit 831401d

Please sign in to comment.