Skip to content

Commit

Permalink
fix copy artifact accessory quota issue (goharbor#17293)
Browse files Browse the repository at this point in the history
It needs to request quota for accessory on copying artifact.

Signed-off-by: wang yan <[email protected]>
  • Loading branch information
wy65701436 authored and sluetze committed Oct 29, 2022
1 parent 02af1fb commit 0de5b32
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
29 changes: 17 additions & 12 deletions src/controller/artifact/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,23 +623,28 @@ func (c *controller) Walk(ctx context.Context, root *Artifact, walkFn func(*Arti
if !walked[child.Digest] {
queue.PushBack(child)
}
if len(child.Accessories) != 0 {
for _, acc := range child.Accessories {
accArt, err := c.Get(ctx, acc.GetData().ArtifactID, option)
if err != nil {
return err
}
if !walked[accArt.Digest] {
queue.PushBack(accArt)
}
}
}
}
}

if len(artifact.Accessories) > 0 {
var ids []int64
for _, acc := range artifact.Accessories {
ids = append(ids, acc.GetData().ArtifactID)
}

children, err := c.List(ctx, q.New(q.KeyWords{"id__in": ids, "base": "*"}), option)
if err != nil {
return err
}

for _, child := range children {
if !walked[child.Digest] {
queue.PushBack(child)
accArt, err := c.Get(ctx, acc.GetData().ArtifactID, option)
if err != nil {
return err
}
if !walked[accArt.Digest] {
queue.PushBack(accArt)
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/server/middleware/quota/copy_artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ func copyArtifactResources(r *http.Request, _, referenceID string) (types.Resour

ctx := r.Context()

art, err := artifactController.GetByReference(ctx, repository, reference, nil)
art, err := artifactController.GetByReference(ctx, repository, reference, &artifact.Option{
WithAccessory: true,
})
if errors.IsNotFoundErr(err) {
// artifact not found, discontinue the API request
return nil, errors.BadRequestError(nil).WithMessage("artifact %s not found", from)
Expand All @@ -103,7 +105,9 @@ func copyArtifactResources(r *http.Request, _, referenceID string) (types.Resour
err = artifactController.Walk(ctx, art, func(a *artifact.Artifact) error {
artifactDigests = append(artifactDigests, a.Digest)
return nil
}, nil)
}, &artifact.Option{
WithAccessory: true,
})
if err != nil {
logger.Errorf("walk the artifact %s failed, error: %v", art.Digest, err)
return nil, err
Expand Down

0 comments on commit 0de5b32

Please sign in to comment.