Skip to content
Open
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
12 changes: 3 additions & 9 deletions src/controller/proxy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,9 @@ func (c *controller) UseLocalManifest(ctx context.Context, art lib.ArtifactInfo,
return false, nil, err
}
if !exist || desc == nil {
dig, err := c.getManifestDigestInLocal(ctx, art)
if err != nil {
// skip to delete when error, use debug level log to avoid too many logs when the manifest is removed from upstream
log.Debugf("failed to get manifest digest in local, error: %v, skip to delete it, art %+v", err, art)
} else {
go func() {
c.local.DeleteManifest(art.Repository, dig)
log.Infof("delete manifest %s with digest %s", art.Repository, dig)
}()
if a != nil { // if not found, use local if it exists, because a exist, otherwise return error
log.Infof("Artifact not found in remote registry but exists in local cache, serving from local: %v:%v", art.Repository, art.Tag)
return true, nil, nil
}
return false, nil, errors.NotFoundError(fmt.Errorf("repo %v, tag %v not found", art.Repository, art.Tag))
}
Expand Down
6 changes: 3 additions & 3 deletions src/controller/proxy/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ func (p *proxyControllerTestSuite) TestUseLocalManifest_429ToLocal() {
p.Assert().True(result)
}

func (p *proxyControllerTestSuite) TestUseLocalManifestWithTag_False() {
func (p *proxyControllerTestSuite) TestUseLocalManifestWithTag_True() {
ctx := context.Background()
art := lib.ArtifactInfo{Repository: "library/hello-world", Tag: "latest"}
desc := &distribution.Descriptor{}
p.local.On("GetManifest", mock.Anything, mock.Anything).Return(&artifact.Artifact{}, nil)
p.remote.On("ManifestExist", mock.Anything, mock.Anything).Return(false, desc, nil)
result, _, err := p.ctr.UseLocalManifest(ctx, art, p.remote)
p.Assert().True(errors.IsNotFoundErr(err))
p.Assert().False(result)
p.Assert().Nil(err)
p.Assert().True(result)
}

func (p *proxyControllerTestSuite) TestUseLocalBlob_True() {
Expand Down