feature(replication) check namespace existing first for AWS adapter

Signed-off-by: Ziming Zhang <zziming@vmware.com>
This commit is contained in:
Ziming Zhang 2020-10-26 16:36:30 +08:00
parent 8535ecbbe5
commit a7d906649c

View File

@ -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,