mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-20 09:15:19 +01:00
Merge pull request #7414 from kofj/optimizing_native_adapter
Optimizing native adapter
This commit is contained in:
commit
a8dae4025c
@ -15,10 +15,8 @@
|
||||
package native
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
common_http "github.com/goharbor/harbor/src/common/http"
|
||||
adp "github.com/goharbor/harbor/src/replication/adapter"
|
||||
"github.com/goharbor/harbor/src/replication/model"
|
||||
"github.com/goharbor/harbor/src/replication/util"
|
||||
@ -42,7 +40,7 @@ func (n native) FetchImages(filters []*model.Filter) ([]*model.Resource, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resources := []*model.Resource{}
|
||||
var resources []*model.Resource
|
||||
for _, repository := range repositories {
|
||||
tags, err := n.filterTags(repository, tagFilterPattern)
|
||||
if err != nil {
|
||||
@ -70,17 +68,8 @@ func (n native) filterRepositories(pattern string) ([]string, error) {
|
||||
// if the pattern contains no "*" and "?", it is a specific repository name
|
||||
// just to make sure the repository exists
|
||||
if len(pattern) > 0 && !strings.ContainsAny(pattern, "*?") {
|
||||
_, err := n.ListTag(pattern)
|
||||
// the repository exists
|
||||
if err == nil {
|
||||
return []string{pattern}, nil
|
||||
}
|
||||
// the repository doesn't exist
|
||||
if e, ok := err.(*common_http.Error); ok && e.Code == http.StatusNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
// other error
|
||||
return nil, err
|
||||
// check is repository exist later at filterTags.
|
||||
return []string{pattern}, nil
|
||||
}
|
||||
// search repositories from catalog api
|
||||
repositories, err := n.Catalog()
|
||||
@ -113,7 +102,7 @@ func (n native) filterTags(repository, pattern string) ([]string, error) {
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
result := []string{}
|
||||
var result []string
|
||||
for _, tag := range tags {
|
||||
match, err := util.Match(pattern, tag)
|
||||
if err != nil {
|
||||
|
@ -70,27 +70,26 @@ func Test_native_FetchImages(t *testing.T) {
|
||||
want []*model.Resource
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: discuss: should we report error if not found in the source native registry.
|
||||
// {
|
||||
// name: "repository not exist",
|
||||
// filters: []*model.Filter{
|
||||
// {
|
||||
// Type: model.FilterTypeName,
|
||||
// Value: "b1",
|
||||
// },
|
||||
// },
|
||||
// wantErr: true,
|
||||
// },
|
||||
// {
|
||||
// name: "tag not exist",
|
||||
// filters: []*model.Filter{
|
||||
// {
|
||||
// Type: model.FilterTypeTag,
|
||||
// Value: "c",
|
||||
// },
|
||||
// },
|
||||
// wantErr: true,
|
||||
// },
|
||||
{
|
||||
name: "repository not exist",
|
||||
filters: []*model.Filter{
|
||||
{
|
||||
Type: model.FilterTypeName,
|
||||
Value: "b1",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "tag not exist",
|
||||
filters: []*model.Filter{
|
||||
{
|
||||
Type: model.FilterTypeTag,
|
||||
Value: "this_tag_not_exist_in_the_mock_server",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "no filters",
|
||||
filters: []*model.Filter{},
|
||||
|
Loading…
Reference in New Issue
Block a user