Skip to content

Commit 17c1cc8

Browse files
committed
cmd-coreos-prune: Add build pruning after other actions
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.
1 parent d422dc6 commit 17c1cc8

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/cmd-coreos-prune

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def main():
112112
builds_json_data = json.load(f)
113113
# Original list of builds
114114
builds = builds_json_data["builds"]
115-
pruned_build_ids = []
115+
builds_to_prune = set()
116116
images_to_keep = policy.get(stream, {}).get("images-keep", [])
117117
barrier_releases = set()
118118
# Get the update graph for stable streams
@@ -137,7 +137,7 @@ def main():
137137
current_build = Build(id=build_id, images=images, arch=arch, meta_json=meta_json)
138138

139139
# Iterate over actions (policy types) to apply pruning
140-
for action in ['cloud-uploads', 'images', 'build', 'containers']:
140+
for action in ['cloud-uploads', 'images', 'containers', 'build']:
141141
if action not in policy[stream]:
142142
continue
143143
action_duration = convert_duration_to_days(policy[stream][action])
@@ -172,8 +172,11 @@ def main():
172172
prune_images(s3_client, current_build, images_to_keep, args.dry_run, bucket, prefix)
173173
# Fully prune releases that are very old including deleting the directory in s3 for that build.
174174
case "build":
175-
prune_build(s3_client, bucket, prefix, build_id, args.dry_run)
176-
pruned_build_ids.append(build_id)
175+
# Since pruning a build prunes s3 for all architectures
176+
# we'll prune later so that we do it only once and we
177+
# make sure we've completed any architecture specific
178+
# operations, (i.e. pruning aarch64 AMIs).
179+
builds_to_prune.add(build_id)
177180
case "containers":
178181
# Our containers are manifest listed, which means deleting the container tag
179182
# for one architecture deletes it for all of them. We'll choose to only prune
@@ -202,12 +205,14 @@ def main():
202205
else:
203206
policy_cleanup[action] = True
204207

205-
if pruned_build_ids:
208+
if builds_to_prune:
209+
for build_id in builds_to_prune:
210+
prune_build(s3_client, bucket, prefix, build_id, args.dry_run)
206211
if "tombstone-builds" not in builds_json_data:
207212
builds_json_data["tombstone-builds"] = []
208213
# Separate the builds into remaining builds and tombstone builds
209-
remaining_builds = [build for build in builds if build["id"] not in pruned_build_ids]
210-
tombstone_builds = [build for build in builds if build["id"] in pruned_build_ids]
214+
remaining_builds = [build for build in builds if build["id"] not in builds_to_prune]
215+
tombstone_builds = [build for build in builds if build["id"] in builds_to_prune]
211216
# Update the data structure
212217
builds_json_data["builds"] = remaining_builds
213218
builds_json_data["tombstone-builds"].extend(tombstone_builds)

0 commit comments

Comments
 (0)