Allow an --exclude tag option or compile against a regexp lib that allows negative look ahead (?!whatever) for purge tasks
What is the problem you're trying to solve We'd like to be able to call acr purge tasks to delete all images older than X days that aren't currently in use on our aks cluster. The current golang library used does not support negative look aheads.
Describe the solution you'd like We'd like to generate an exclude list via:
kubectl get pods --all-namespaces -o=jsonpath="{..image}" -l app=<appName>
And feed that to acr purge with either an --exclude-tag or a negative lookahead regex on --filter
Additional context
Error: failed to dry-run purge: error parsing regexp: invalid or unsupported Perl syntax: `(?!`
This will be really usefull. Any plans to support this feature?
There was this PR https://github.com/Azure/acr-cli/pull/60 which has the capabilities to exclude. Why was it closed?
Is there a possibility to get this function? I mean, how we can help to get it in a short term. The negative lookahead RegEx are quite useful for tasks when you want to keep some images that matches with some specific pattern.
Using the following it gives me the same error:
az acr run --cmd "acr purge --filter 'yyy:(?!dev$).*' --untagged --ago 0d --keep 0 --dry-run" --registry zzzz /dev/null
Deleting tags for repository: yyy Error: failed to dry-run purge: error parsing regexp: invalid or unsupported Perl syntax: (?! 2021/09/13 10:13:18 Container failed during run: acb_step_0. No retries remaining. failed to run step ID: acb_step_0: exit status 1
Anybody has a quick walk-around?
I don't like to bump stuff, but regarding the age of the issue: Could we please get any feedback for this? "delete all except x" feels like a common use case to me.
As for a workaround: Following this Stackoverflow answer I wrote a PowerShell script that creates an expression without lookups:
$test = "latest"
$conditions = (0..$test.length | % {
$prev = $test.Remove($_)
if ($_ -eq $test.length) { "$prev.+" }
else { "$prev(|[^$($test[$_])].*)" }
}) -join "|"
$actual = "^($conditions)$"
# test whether `$actual works:
$expected = "^((|[^l].*)|l(|[^a].*)|la(|[^t].*)|lat(|[^e].*)|late(|[^s].*)|lates(|[^t].*)|latest.+)$"
Write-Host ($expected -eq $actual)
You can use this script for acr purge to delete all tags except the given one. This only works for one tag.
Really need this feature. :(
Another vote for this feature. Similar use case as above: I need to prevent the acr purge command from removing anything with the latest tag.
Voting for this too for the same reason to omit the latest tag.
Voting to exclude specific tags
It seems that if you enclose the regex into ^ and $ characters, the negative lookahead works now.
Example - persist "latest" and "release-*" tags on all images:
az acr run --registry xxx.azurecr.io --cmd 'acr purge --registry xxx.azurecr.io --ago 0d --untagged --filter ".*:^(?!^latest$|^release-).*$" --dry-run' /dev/null