-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New options for keeping images #10
Conversation
Hi Julian, thanks for your contribution. Here are a few thought of mine, but Halil has to decide ;) The option to filter by a tag name is a good idea. But I would prefer to name the option But maybe we dont need an additional flag at all. Lets say we would allow In cleanreg.py we check if there is a ":" in the reponame. If yes, we need to check the tagname. Then we could add a I think, if we add more features to the configfile, then we should better switch to a json file. The underscores are not very readable. And maybe we need to change the testframework, when we add more and more tests. I think, it was not my best idea to use shunit :D It's a bit tricky |
cleanreg.py
Outdated
# check if date is valid | ||
if args.date is not None: | ||
try: | ||
datetime.strptime(args.date, '%d.%m.%Y') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should better be an ISO date format, maybe allow day (2018-05-31) and datetime (2018-05-31T18:03:24+00:00)
cleanreg.py
Outdated
@@ -55,6 +56,8 @@ def parse_arguments(): | |||
parser.add_argument('-k', '--keepimages', help="Amount of images (not tags!) which should be kept " | |||
"for the given repo (if -n is set) or for each repo of the " | |||
"registry (if -cf is set).", type=int) | |||
parser.add_argument('-re', '--regex', help="Image tags matching the regular expression will be kept", default=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my other comment. I think this flag should only enable regex and not define the tagname. The tagname can be part of of the reponame, e.g postgres:3.6
where postgres is the image name and 3.6 the tag
cleanreg.py
Outdated
@@ -55,6 +56,8 @@ def parse_arguments(): | |||
parser.add_argument('-k', '--keepimages', help="Amount of images (not tags!) which should be kept " | |||
"for the given repo (if -n is set) or for each repo of the " | |||
"registry (if -cf is set).", type=int) | |||
parser.add_argument('-re', '--regex', help="Image tags matching the regular expression will be kept", default=None) | |||
parser.add_argument('-d', '--date', help="Keep images which were created since this date. Format: dd.mm.yyyy", default=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better --after
, then we could also add a --before
cleanreg.py
Outdated
if date is not None and date != "_" and date != "": | ||
parsed_date = datetime.strptime(date, '%d.%m.%Y') | ||
for tag in deletion_tags.keys(): | ||
tag_date = datetime.strptime(deletion_tags[tag]['date'].split('T')[0], '%Y-%m-%d') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better interpret the full datetime string (with the T). You can search for ISO Datetime
cleanreg.py
Outdated
@@ -597,13 +632,13 @@ def get_deletiontags(verbose, tags_dates_digests, repo, repo_count): | |||
|
|||
repo_del_tags = {} | |||
repo_del_digests = {} | |||
for repo, count in repos_counts.iteritems(): | |||
for repo, (count, regex, date) in repos_counts.iteritems(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regex
should better be tagname
Sorry coming again so late (just again not get pinged by Github...). |
PTAL @JulianSauer |
Hey, I've added most of the suggestions from @kekru:
|
cleanreg.py
Outdated
@@ -89,8 +110,9 @@ def parse_arguments(): | |||
parser.error("[-n] and [-cf] cant be used together") | |||
|
|||
# hackish dependent arguments | |||
if (bool(args.reponame) or args.clean_full_catalog) ^ (args.keepimages is not None): | |||
parser.error("[-n] or [-cf] have to be used together with [-k].") | |||
if (bool(args.reponame) or args.clean_full_catalog) ^ (args.keepimages is not 0 or args.regex is True or args.since is not None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a small comment for this check and the check beneath would be nice, to better understand
cleanreg.py
Outdated
|
||
deletion_tags = all_tags | ||
if regex and tagname != "": | ||
deletion_tags = {k: deletion_tags[k] for k in deletion_tags if re.match(tagname, k)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crazy python syntax, what do I have to search for, to find an explanation? :)
cleanreg.py
Outdated
try: | ||
parsed_date = datetime.strptime(args.since, '%Y%m%dT%H%M%S') | ||
except ValueError: | ||
parsed_date = datetime.strptime(args.since, '%Y-%m-%dT%H:%M:%S') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the date parsing could be extracted to a function (returning the parsed date or None if not parsable), because you need it two times
cleanreg.py
Outdated
if ammount_tags <= keep_count: | ||
deletion_tags.clear() | ||
else: | ||
deletion_tags = collections.OrderedDict(islice(deletion_tags.iteritems(), ammount_tags - keep_count)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah comment would be great.
if amount_tags - keep_count
is 7, then this will keep the first 7 in the list and remove the others. The first 7 are the oldest tags.
Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deletion_tags
contains the tags that will be deleted. So it will remove the 7 oldest and keep the others.
(I'll add a comment)
I've changed a few more things considering the suggestions of @kekru (Simplified a for loop, moved date parsing to a function and added comments). |
Looks fine, thank you. I'll add some additional stuff into the README before I create a new release. |
I've added options to keep tags if they match a regular expression or if they were created after a specified date. E.g.:
./cleanreg.py -r http://192.168.56.2:5000 -n mysql -k 5 -i
-re .*release.* -d 01.01.2018
will keep the 5 latest but also tags containing the word "release" as well as all those created since 01.01.2018.
Configs have to be rewritten to match the additional parameters with the option to use an underscore to ignore the parameter:
<repo> <k> <re> <d>
E.g.:
mysql 5 _ _
keeps the 5 latest and does not consider regular expressions or dates.