acr-cli icon indicating copy to clipboard operation
acr-cli copied to clipboard

Allow an --exclude tag option or compile against a regexp lib that allows negative look ahead (?!whatever) for purge tasks

Open dominicdejacomo opened this issue 6 years ago • 11 comments

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: `(?!`

dominicdejacomo avatar Oct 07 '19 23:10 dominicdejacomo

This will be really usefull. Any plans to support this feature?

alexiacobws avatar Jun 02 '20 10:06 alexiacobws

There was this PR https://github.com/Azure/acr-cli/pull/60 which has the capabilities to exclude. Why was it closed?

Steve-hyas avatar Jan 12 '21 19:01 Steve-hyas

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.

fiv21 avatar Aug 20 '21 15:08 fiv21

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?

dudubis avatar Sep 13 '21 10:09 dudubis

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.

johannespetereit avatar Mar 15 '22 15:03 johannespetereit

Really need this feature. :(

tgolly avatar Aug 24 '22 07:08 tgolly

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.

toby-coleman avatar Mar 06 '23 12:03 toby-coleman

Voting for this too for the same reason to omit the latest tag.

Swaps76 avatar May 22 '23 08:05 Swaps76

Voting to exclude specific tags

cakriwut avatar Apr 15 '24 07:04 cakriwut

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

cek-cek avatar Apr 22 '24 14:04 cek-cek