mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-11 01:11:25 +01:00
feature(replication) check namespace existing first for AWS adapter
Signed-off-by: Ziming Zhang <zziming@vmware.com>
This commit is contained in:
parent
8535ecbbe5
commit
a7d906649c
@ -227,7 +227,15 @@ func (a *adapter) PrepareForPush(resources []*model.Resource) error {
|
|||||||
return errors.New("the name of the namespace cannot be nil")
|
return errors.New("the name of the namespace cannot be nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := a.createRepository(resource.Metadata.Repository.Name)
|
exist, err := a.checkRepository(resource.Metadata.Repository.Name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if exist {
|
||||||
|
log.Infof("Namespace %s already exist in AWS ECR, skip it.", resource.Metadata.Repository.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
err = a.createRepository(resource.Metadata.Repository.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -235,6 +243,19 @@ func (a *adapter) PrepareForPush(resources []*model.Resource) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *adapter) checkRepository(repository string) (exists bool, err error) {
|
||||||
|
out, err := a.cacheSvc.DescribeRepositories(&awsecrapi.DescribeRepositoriesInput{
|
||||||
|
RepositoryNames: []*string{&repository},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if len(out.Repositories) > 0 {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *adapter) createRepository(repository string) error {
|
func (a *adapter) createRepository(repository string) error {
|
||||||
_, err := a.cacheSvc.CreateRepository(&awsecrapi.CreateRepositoryInput{
|
_, err := a.cacheSvc.CreateRepository(&awsecrapi.CreateRepositoryInput{
|
||||||
RepositoryName: &repository,
|
RepositoryName: &repository,
|
||||||
|
Loading…
Reference in New Issue
Block a user