mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-12 18:01:54 +01:00
Merge pull request #803 from ywk253100/buf_fix_filter_repo
bug fix: handle error when checking the existence of repos whose project does not exist in Harbor
This commit is contained in:
commit
e6b3638f9c
52
api/utils.go
52
api/utils.go
@ -265,7 +265,11 @@ func SyncRegistry() error {
|
||||
|
||||
var reposToAdd []string
|
||||
var reposToDel []string
|
||||
reposToAdd, reposToDel = diffRepos(reposInRegistry, reposInDB)
|
||||
reposToAdd, reposToDel, err = diffRepos(reposInRegistry, reposInDB)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(reposToAdd) > 0 {
|
||||
log.Debugf("Start adding repositories into DB... ")
|
||||
for _, repoToAdd := range reposToAdd {
|
||||
@ -311,37 +315,15 @@ func catalog() ([]string, error) {
|
||||
return repositories, err
|
||||
}
|
||||
|
||||
repos, err := rc.Catalog()
|
||||
repositories, err = rc.Catalog()
|
||||
if err != nil {
|
||||
return repositories, err
|
||||
}
|
||||
|
||||
for _, repo := range repos {
|
||||
// TODO remove the workaround when the bug of registry is fixed
|
||||
// TODO read it from config
|
||||
endpoint := os.Getenv("REGISTRY_URL")
|
||||
client, err := cache.NewRepositoryClient(endpoint, true,
|
||||
"admin", repo, "repository", repo)
|
||||
if err != nil {
|
||||
return repositories, err
|
||||
}
|
||||
|
||||
exist, err := repositoryExist(repo, client)
|
||||
if err != nil {
|
||||
return repositories, err
|
||||
}
|
||||
|
||||
if !exist {
|
||||
continue
|
||||
}
|
||||
|
||||
repositories = append(repositories, repo)
|
||||
}
|
||||
|
||||
return repositories, nil
|
||||
}
|
||||
|
||||
func diffRepos(reposInRegistry []string, reposInDB []string) ([]string, []string) {
|
||||
func diffRepos(reposInRegistry []string, reposInDB []string) ([]string, []string, error) {
|
||||
var needsAdd []string
|
||||
var needsDel []string
|
||||
|
||||
@ -366,6 +348,24 @@ func diffRepos(reposInRegistry []string, reposInDB []string) ([]string, []string
|
||||
continue
|
||||
}
|
||||
|
||||
// TODO remove the workaround when the bug of registry is fixed
|
||||
// TODO read it from config
|
||||
endpoint := os.Getenv("REGISTRY_URL")
|
||||
client, err := cache.NewRepositoryClient(endpoint, true,
|
||||
"admin", repoInR, "repository", repoInR)
|
||||
if err != nil {
|
||||
return needsAdd, needsDel, err
|
||||
}
|
||||
|
||||
exist, err = repositoryExist(repoInR, client)
|
||||
if err != nil {
|
||||
return needsAdd, needsDel, err
|
||||
}
|
||||
|
||||
if !exist {
|
||||
continue
|
||||
}
|
||||
|
||||
needsAdd = append(needsAdd, repoInR)
|
||||
} else if d > 0 {
|
||||
needsDel = append(needsDel, repoInD)
|
||||
@ -396,7 +396,7 @@ func diffRepos(reposInRegistry []string, reposInDB []string) ([]string, []string
|
||||
j++
|
||||
}
|
||||
|
||||
return needsAdd, needsDel
|
||||
return needsAdd, needsDel, nil
|
||||
}
|
||||
|
||||
func projectExists(repository string) (bool, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user