Created
August 9, 2019 15:10
-
-
Save zhsj/f3511cf48cd13b1246045ba0b9c196d4 to your computer and use it in GitHub Desktop.
clean containerd cri images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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