Feature: added exclude-filter argument to keep certain image tags#60
Feature: added exclude-filter argument to keep certain image tags#60angrox wants to merge 8 commits intoAzure:masterfrom
Conversation
Resolved possible shadowinf or err variable
| | Untag tags that include hello-world in their name | --filter `"<repository>:hello-world"` | | ||
| | Untag all tags that are older than the duration | --filter `"<repository>:.*"` | | ||
|
|
||
| | Exclude all tags from untagging that end with -prod | --exclude-filter `".*-prod$"` | |
|
|
||
| ##### Exclude filter tag | ||
|
|
||
| To exclude tags from untagging one or more --exclude-filter arguments can be added |
There was a problem hiding this comment.
nit: --exclude-filter for better representation.
| } | ||
| isExcluded := false | ||
| for _, exFilter := range excludeFilter { | ||
| exFilterRegex, exFilterErr := regexp.Compile(exFilter) |
There was a problem hiding this comment.
exFilter is complied unnecessarily multiple times. You should pre-compile it like filter.
| acrClient api.AcrCLIClientInterface, | ||
| repoName string, | ||
| filter *regexp.Regexp, | ||
| excludeFilter []string, |
There was a problem hiding this comment.
You should pass a *regexp.Regexp instead of []string for excludeFilter. The reason is explained in the next comment.
| continue | ||
| } | ||
| } | ||
| if isExcluded { |
There was a problem hiding this comment.
Once the excludeFilter is a *regexp.Regexp, the variable isExcluded can be simplified.
| mockClient := &mocks.AcrCLIClientInterface{} | ||
| mockClient.On("GetAcrTags", testCtx, testRepo, "", "").Return(notFoundTagResponse, errors.New("testRepo not found")).Once() | ||
| deletedTags, err := purgeTags(testCtx, mockClient, testLoginURL, testRepo, "1d", "[\\s\\S]*") | ||
| deletedTags, err := purgeTags(testCtx, mockClient, testLoginURL, testRepo, "1d", "[\\s\\S]*", nil) |
There was a problem hiding this comment.
You need real test cases instead of simply passing nil to it.
|
How can we help to get this implemented in the short term? 🤔 |
|
Hello @northtyphoon , why was this MR closed ? Can we finish the work (I can try if needed) :) |
Purpose of the PR
Golang does not support the full capability of perl regex to filter image tags, e.g. to negate a regex. A new flag is added to exclude tags found by the --filter argument. This is useful when you want to keep certain images, e.g. all image tags which are currently in use by a K8s cluster.
Fixes #