Skip to content

Commit 831401d

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 831401d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/cmd-coreos-prune

Lines changed: 8 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 = []
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,7 @@ 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+
builds_to_prune.append(build_id)
177176
case "containers":
178177
# Our containers are manifest listed, which means deleting the container tag
179178
# for one architecture deletes it for all of them. We'll choose to only prune
@@ -202,12 +201,14 @@ def main():
202201
else:
203202
policy_cleanup[action] = True
204203

205-
if pruned_build_ids:
204+
if builds_to_prune:
205+
for build_id in builds_to_prune:
206+
prune_build(s3_client, bucket, prefix, build_id, args.dry_run)
206207
if "tombstone-builds" not in builds_json_data:
207208
builds_json_data["tombstone-builds"] = []
208209
# 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]
210+
remaining_builds = [build for build in builds if build["id"] not in builds_to_prune]
211+
tombstone_builds = [build for build in builds if build["id"] in builds_to_prune]
211212
# Update the data structure
212213
builds_json_data["builds"] = remaining_builds
213214
builds_json_data["tombstone-builds"].extend(tombstone_builds)

0 commit comments

Comments
 (0)