mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-25 10:07:43 +01:00
fix 16883 (#16911)
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:
parent
ecc8c59101
commit
d26b5792c0
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user