Skip to content

Instantly share code, notes, and snippets.

@zhsj
Created August 9, 2019 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhsj/f3511cf48cd13b1246045ba0b9c196d4 to your computer and use it in GitHub Desktop.
Save zhsj/f3511cf48cd13b1246045ba0b9c196d4 to your computer and use it in GitHub Desktop.
clean containerd cri images
#!/usr/bin/python3
import json
import itertools
import subprocess
out = subprocess.check_output(["crictl", "images", "-o", "json"])
images = json.loads(out.decode("utf-8"))
tags = itertools.chain.from_iterable([i["repoTags"] for i in images["images"]])
for repo, repo_tags in itertools.groupby(tags, lambda x: "".join(x.split(":")[:-1])):
old_tags = sorted(repo_tags, key=lambda x: x.split(":")[-1])[:-1]
for tag in old_tags:
subprocess.run(["crictl", "rmi", tag])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment