From e382bb616b98210d8c7a25fb1bc53898d0725496 Mon Sep 17 00:00:00 2001 From: Dan Mick Date: Tue, 2 Feb 2021 08:19:44 +0000 Subject: [PATCH] prune-quay.py: fix deletion of busy ref names (master etc.) We must only delete the ref name if it refers to the same image as the ref-shortsha1-el form of the name; if it's been pushed as a new build of ref from a new sha1, it's no longer the image we need to delete. Verify the ref tag points to the same image as the ref-shortsha1-el tag. Signed-off-by: Dan Mick --- quay-pruner/build/prune-quay.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/quay-pruner/build/prune-quay.py b/quay-pruner/build/prune-quay.py index 7d0787f54..670369135 100755 --- a/quay-pruner/build/prune-quay.py +++ b/quay-pruner/build/prune-quay.py @@ -237,7 +237,20 @@ def main(): print('Marking %s for deletion' % name) tags_to_delete.add(name) if ref: - tags_to_delete.add(ref) + # the ref tag may already have been overwritten by a new + # build of the same ref, but a different sha1. Delete it only + # if it refers to the same image_id as the full tag. + names_of_same_image = \ + [t['name'] for t in quaytags + if t['image_id'] == tag['image_id']] + if ref in names_of_same_image: + if args.verbose: + print('Marking %s for deletion' % name) + tags_to_delete.add(name) + else: + if args.verbose: + print('Skipping %s: not in %s' % + (name, names_of_same_image)) if short_sha1: if args.verbose: print('Marking %s for 2nd-pass deletion' % short_sha1) -- 2.47.3