mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-05 14:31:37 +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")
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@ -235,6 +243,19 @@ func (a *adapter) PrepareForPush(resources []*model.Resource) error {
|
||||
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 {
|
||||
_, err := a.cacheSvc.CreateRepository(&awsecrapi.CreateRepositoryInput{
|
||||
RepositoryName: &repository,
|
||||
|
Loading…
Reference in New Issue
Block a user