Fixes #16883, set the labels belonging to the subject manifest to the accessories on replication.

Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2022-05-26 01:30:53 +08:00 committed by GitHub
parent ecc8c59101
commit d26b5792c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,7 @@ import (
"github.com/goharbor/harbor/src/common/utils"
"github.com/goharbor/harbor/src/controller/artifact"
"github.com/goharbor/harbor/src/lib/encode/repository"
labelmodel "github.com/goharbor/harbor/src/pkg/label/model"
"github.com/goharbor/harbor/src/pkg/reg/adapter/harbor/base"
"github.com/goharbor/harbor/src/pkg/reg/model"
repomodel "github.com/goharbor/harbor/src/pkg/repository/model"
@ -57,13 +58,17 @@ func (c *client) listArtifacts(repo string) ([]*model.Artifact, error) {
var arts []*model.Artifact
// append the accessory objects behind the subject artifact if it has.
var getAccessoryArts = func(art *artifact.Artifact) ([]*model.Artifact, error) {
var getAccessoryArts = func(art *artifact.Artifact, labels []*labelmodel.Label) ([]*model.Artifact, error) {
var accArts = []*model.Artifact{}
for _, acc := range art.Accessories {
accArt := &model.Artifact{
Type: art.Type,
Digest: acc.GetData().Digest,
}
// set the labels belonging to the subject manifest to the accessories.
for _, label := range labels {
accArt.Labels = append(accArt.Labels, label.Name)
}
tags, err := c.listTags(project, repo, acc.GetData().Digest)
if err != nil {
return nil, err
@ -91,7 +96,7 @@ func (c *client) listArtifacts(repo string) ([]*model.Artifact, error) {
arts = append(arts, art)
// append the accessory of index or individual artifact
accArts, err := getAccessoryArts(artItem)
accArts, err := getAccessoryArts(artItem, artItem.Labels)
if err != nil {
return nil, err
}
@ -105,7 +110,7 @@ func (c *client) listArtifacts(repo string) ([]*model.Artifact, error) {
if err := c.C.Get(url, &artRef); err != nil {
return nil, err
}
accArts, err := getAccessoryArts(&artRef)
accArts, err := getAccessoryArts(&artRef, artItem.Labels)
if err != nil {
return nil, err
}