fix copy artifact accessory quota issue (#17315)

It needs to request quota for accessory on copying artifact.

Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2022-08-04 10:08:24 +08:00 committed by GitHub
parent 7cf50ccc59
commit 4696f46b92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 14 deletions

View File

@ -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)
}
}
}

View File

@ -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)
@ -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