mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-16 11:51:47 +01:00
fix accessory replication issue (#18471)
Fixes #18404 Support multiple level accessories replication. Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
parent
de20659da5
commit
60d9664cbc
@ -59,33 +59,6 @@ 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, labels []*labelmodel.Label, tags []*ctltag.Tag) ([]*model.Artifact, error) {
|
||||
var accArts = []*model.Artifact{}
|
||||
for _, acc := range art.Accessories {
|
||||
accArt := &model.Artifact{
|
||||
Type: art.Type,
|
||||
Digest: acc.GetData().Digest,
|
||||
IsAcc: true,
|
||||
}
|
||||
for _, tag := range tags {
|
||||
accArt.ParentTags = append(accArt.ParentTags, tag.Name)
|
||||
}
|
||||
// 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
|
||||
}
|
||||
accArt.Tags = append(accArt.Tags, tags...)
|
||||
|
||||
accArts = append(accArts, accArt)
|
||||
}
|
||||
return accArts, nil
|
||||
}
|
||||
|
||||
for _, artItem := range artifacts {
|
||||
art := &model.Artifact{
|
||||
Type: artItem.Type,
|
||||
@ -100,8 +73,8 @@ 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, artItem.Labels, artItem.Tags)
|
||||
if err != nil {
|
||||
accArts := make([]*model.Artifact, 0)
|
||||
if err := c.getAccessoryArts(project, repo, artItem, artItem.Labels, artItem.Tags, &accArts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
arts = append(arts, accArts...)
|
||||
@ -114,8 +87,8 @@ 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, artItem.Labels, artItem.Tags)
|
||||
if err != nil {
|
||||
accArts := make([]*model.Artifact, 0)
|
||||
if err := c.getAccessoryArts(project, repo, &artRef, artItem.Labels, artItem.Tags, &accArts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
arts = append(arts, accArts...)
|
||||
@ -124,6 +97,36 @@ func (c *client) listArtifacts(repo string) ([]*model.Artifact, error) {
|
||||
return arts, nil
|
||||
}
|
||||
|
||||
func (c *client) getAccessoryArts(project, repo string, art *artifact.Artifact, labels []*labelmodel.Label, tags []*ctltag.Tag, accArts *[]*model.Artifact) error {
|
||||
for _, acc := range art.Accessories {
|
||||
accArt := &model.Artifact{
|
||||
Type: art.Type,
|
||||
Digest: acc.GetData().Digest,
|
||||
IsAcc: true,
|
||||
}
|
||||
for _, tag := range tags {
|
||||
accArt.ParentTags = append(accArt.ParentTags, tag.Name)
|
||||
}
|
||||
// set the labels belonging to the subject manifest to the accessories.
|
||||
for _, label := range labels {
|
||||
accArt.Labels = append(accArt.Labels, label.Name)
|
||||
}
|
||||
// recursively get the accessories of the accessory
|
||||
art, err := c.getArtifact(project, repo, acc.GetData().Digest, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, tag := range art.Tags {
|
||||
accArt.Tags = append(accArt.Tags, tag.Name)
|
||||
}
|
||||
*accArts = append(*accArts, accArt)
|
||||
if err != c.getAccessoryArts(project, repo, art, labels, tags, accArts) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *client) listTags(project, repo, digest string) ([]string, error) {
|
||||
tags := []*tagmodel.Tag{}
|
||||
url := fmt.Sprintf("%s/projects/%s/repositories/%s/artifacts/%s/tags",
|
||||
@ -138,6 +141,16 @@ func (c *client) listTags(project, repo, digest string) ([]string, error) {
|
||||
return tagNames, nil
|
||||
}
|
||||
|
||||
func (c *client) getArtifact(project, repo, digest string, withAccessory bool) (*artifact.Artifact, error) {
|
||||
url := fmt.Sprintf("%s/projects/%s/repositories/%s/artifacts/%s?with_accessory=%t&with_tag=true",
|
||||
c.BasePath(), project, repo, digest, withAccessory)
|
||||
artifact := &artifact.Artifact{}
|
||||
if err := c.C.Get(url, &artifact); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return artifact, nil
|
||||
}
|
||||
|
||||
func (c *client) deleteTag(repo, tag string) error {
|
||||
project, repo := utils.ParseRepository(repo)
|
||||
repo = repository.Encode(repo)
|
||||
|
Loading…
Reference in New Issue
Block a user