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

Log ensureArtifact ConflictErr #19294

Merged
merged 5 commits into from
Jan 15, 2024
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
1 change: 1 addition & 0 deletions src/controller/artifact/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func (c *controller) ensureArtifact(ctx context.Context, repository, digest stri
if !errors.IsConflictErr(err) {
return false, nil, err
}
log.Debugf("failed to create artifact %s@%s: %v", repository, digest, err)
// if got conflict error, try to get the artifact again
artifact, err = c.artMgr.GetByDigest(ctx, repository, digest)
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions src/controller/artifact/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,21 @@ func (c *controllerTestSuite) TestEnsureArtifact() {
c.Require().Nil(err)
c.True(created)
c.Equal(int64(1), art.ID)

// reset the mock
c.SetupTest()

// the artifact doesn't exist and get a conflict error on creating the artifact and fail to get again
c.repoMgr.On("GetByName", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{
ProjectID: 1,
}, nil)
c.artMgr.On("GetByDigest", mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.NotFoundError(nil))
c.artMgr.On("Create", mock.Anything, mock.Anything).Return(int64(1), errors.ConflictError(nil))
c.abstractor.On("AbstractMetadata").Return(nil)
created, art, err = c.ctl.ensureArtifact(orm.NewContext(nil, &ormtesting.FakeOrmer{}), "library/hello-world", digest)
c.Require().Error(err, errors.NotFoundError(nil))
c.False(created)
c.Require().Nil(art)
}

func (c *controllerTestSuite) TestEnsure() {
Expand Down
Loading