fix: image retention policy to handle patterns even if metadb is not instantiated (#3200)

It is to fix #3185.
This fixes the case where MetaDB is not instantiated (none of the conditions match),
and we want to retain tags only by pattern (which should not need to use MetaBD).

Without this fix you could only use retention to delete untagged manifests.
If you specified only the key "patterns" under "keepTags", zot would crash.
It was possible to not specify "keepTags" all, which would retain all tags,
but it was not possible to retains specific tags.

Basically the case quoted below, from the documentation, was broken::
https://zotregistry.dev/v2.1.4/articles/retention/#configuration-example

```
When you specify a regex pattern with no rules other than the default, all tags matching the pattern are retained.
```

This would only work if MetaDb was instantiated by an unrelated configured feature.

Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
This commit is contained in:
Andrei Aaron
2025-06-15 07:38:52 +03:00
committed by GitHub
parent 6a22640bfa
commit e7a5e09214
5 changed files with 958 additions and 10 deletions
+2 -1
View File
@@ -22,7 +22,8 @@ type PolicyManager interface {
HasDeleteReferrer(repo string) bool
HasDeleteUntagged(repo string) bool
HasTagRetention(repo string) bool
GetRetainedTags(ctx context.Context, repoMeta mTypes.RepoMeta, index ispec.Index) []string
GetRetainedTagsFromIndex(ctx context.Context, repo string, index ispec.Index) []string
GetRetainedTagsFromMetaDB(ctx context.Context, repoMeta mTypes.RepoMeta, index ispec.Index) []string
}
type Rule interface {