RedHatQE / cloudwash

A cloud resources cleanup utility tool
Apache License 2.0
24 stars 29 forks source link

Delete Pattern based on names should be regex based #102

Open jyejare opened 1 year ago

jyejare commented 1 year ago
          Maybe this comes from an intent to have the default behavior pick all images for removal if the `delete_pattern` is empty?

Either way, it needs to be adjusted so delete_pattern is applied correctly when present - I would recommend actually using re here and actually accept a pattern string. Using just startswith will immediately limit the use and dictate that any teams wanting to use this tool have to prefix image names.

re.compile can be used to create the regex pattern object (and to parse the pattern from config), and then you can use Pattern.search function in the list comprehension to indicate whether the given pattern is anywhere in the string. match can be used too, but will be more explicit and will require the caller to specify .* in their pattern to match anywhere in the string. I think either function is fine here, but the docblock/readme/config comment should explain which is in use.

_Originally posted by @mshriver in https://github.com/RedHatQE/cloudwash/pull/101#discussion_r1279358830_