Skip to content

Commit

Permalink
fix: digest different return needsRemote
Browse files Browse the repository at this point in the history
  • Loading branch information
ervitis committed Jan 12, 2024
1 parent cbc665b commit 39f1a46
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
21 changes: 15 additions & 6 deletions pkg/skaffold/build/cache/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,22 @@ func (c *cache) lookupRemote(ctx context.Context, hash, tag string, platforms []
entry := ImageDetails{}

if digest, err := docker.RemoteDigest(tag, c.cfg, nil); err == nil {
log.Entry(ctx).Debugf("Found %s remote", tag)
entry.Digest = digest
fqn := tag + "@" + digest
log.Entry(ctx).Debugf("Looking up %s tag with the full fqn %s for caching", tag, entry.Digest)
if remoteDigest, err := docker.RemoteDigest(fqn, c.cfg, nil); err == nil {
if remoteDigest != digest {
log.Entry(ctx).Debugf("Needs remote tag %s", tag)
return needsRemoteTagging{hash: hash, tag: tag, digest: digest, platforms: platforms}
}
log.Entry(ctx).Debugf("Found %s remote", tag)
entry.Digest = digest

c.cacheMutex.Lock()
c.artifactCache[hash] = entry
c.cacheMutex.Unlock()
return found{hash: hash}
}

c.cacheMutex.Lock()
c.artifactCache[hash] = entry
c.cacheMutex.Unlock()
return found{hash: hash}
}

c.cacheMutex.RLock()
Expand Down
27 changes: 9 additions & 18 deletions pkg/skaffold/build/cache/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,30 +174,21 @@ func TestLookupRemote(t *testing.T) {
expected: needsRemoteTagging{hash: "hash", tag: "fqn_tag", digest: "otherdigest"},
},
{
description: "found locally",
hasher: mockHasher{"hash"},
cache: map[string]ImageDetails{
"hash": {ID: "imageID"},
},
api: (&testutil.FakeAPIClient{}).Add("no_remote_tag", "imageID"),
tag: "no_remote_tag",
expected: needsPushing{hash: "hash", tag: "no_remote_tag", imageID: "imageID"},
},
{
description: "not found",
hasher: mockHasher{"hash"},
cache: map[string]ImageDetails{
"hash": {ID: "imageID"},
},
api: &testutil.FakeAPIClient{},
tag: "no_remote_tag",
expected: needsBuilding{hash: "hash"},
description: "same tag with different hash, no hit",
hasher: mockHasher{"hashhash"},
api: (&testutil.FakeAPIClient{}).Add("latest", "imageID"),
tag: "latest",
expected: needsRemoteTagging{hash: "hashhash", tag: "latest", digest: "digest"},
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
t.Override(&docker.RemoteDigest, func(identifier string, _ docker.Config, _ []specs.Platform) (string, error) {
switch {
case identifier == "latest":
return "digest", nil
case identifier == "latest@digest":
return "otherlatestdigest", nil
case identifier == "tag":
return "digest", nil
case identifier == "fqn_tag@otherdigest":
Expand Down

0 comments on commit 39f1a46

Please sign in to comment.