Skip to content
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

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

Open
dominicdejacomo opened this issue Oct 7, 2019 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@dominicdejacomo
Copy link

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 dominicdejacomo added the enhancement New feature or request label Oct 7, 2019
@alexiacobws
Copy link

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

@Steve-hyas
Copy link

There was this PR #60 which has the capabilities to exclude. Why was it closed?

@fiv21
Copy link

fiv21 commented Aug 20, 2021

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.

@dudubis
Copy link

dudubis commented Sep 13, 2021

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?

@johannespetereit
Copy link

johannespetereit commented Mar 15, 2022

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.

@tgolly
Copy link

tgolly commented Aug 24, 2022

Really need this feature. :(

@toby-coleman
Copy link

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.

@Swaps76
Copy link

Swaps76 commented May 22, 2023

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

@cakriwut
Copy link

Voting to exclude specific tags

@cek-cek
Copy link

cek-cek commented Apr 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests