Merge pull request #13361 from bitsf/aws_adapter_namespace_check

feature(replication) check namespace existing first for AWS adapter
This commit is contained in:
Wenkai Yin(尹文开) 2020-11-02 16:56:50 +08:00 committed by GitHub
commit dd3ffd4147
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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,