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

[cherry-pick] Cache image list with digest key #19838

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/controller/proxy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@
if c.cache == nil {
return a != nil && string(desc.Digest) == a.Digest, nil, nil // digest matches
}

// Pass digest to the cache key, digest is more stable than tag, because tag could be updated
if len(art.Digest) == 0 {
art.Digest = string(desc.Digest)
}

Check warning on line 189 in src/controller/proxy/controller.go

View check run for this annotation

Codecov / codecov/patch

src/controller/proxy/controller.go#L187-L189

Added lines #L187 - L189 were not covered by tests
err = c.cache.Fetch(ctx, manifestListKey(art.Repository, art), &content)
if err != nil {
if errors.Is(err, cache.ErrNotFound) {
Expand Down Expand Up @@ -318,8 +321,8 @@
}

func getReference(art lib.ArtifactInfo) string {
if len(art.Tag) > 0 {
return art.Tag
if len(art.Digest) > 0 {
return art.Digest
}
return art.Digest
return art.Tag
}
2 changes: 1 addition & 1 deletion src/controller/proxy/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func TestGetRef(t *testing.T) {
{
name: `normal`,
in: lib.ArtifactInfo{Repository: "hello-world", Tag: "latest", Digest: "sha256:aabbcc"},
want: "latest",
want: "sha256:aabbcc",
},
{
name: `digest_only`,
Expand Down
5 changes: 4 additions & 1 deletion src/controller/proxy/manifestcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@
log.Errorf("failed to get reference, reference is empty, skip to cache manifest list")
return
}
// some registry will not return the digest in the HEAD request, if no digest returned, cache manifest list content with tag
// cache key should contain digest if digest exist
if len(art.Digest) == 0 {
art.Digest = string(digest.FromBytes(payload))
}

Check warning on line 79 in src/controller/proxy/manifestcache.go

View check run for this annotation

Codecov / codecov/patch

src/controller/proxy/manifestcache.go#L77-L79

Added lines #L77 - L79 were not covered by tests
key := manifestListKey(art.Repository, art)
log.Debugf("cache manifest list with key=cache:%v", key)
if err := m.cache.Save(ctx, manifestListContentTypeKey(art.Repository, art), contentType, manifestListCacheInterval); err != nil {
Expand Down
Loading