Skip to content
This repository was archived by the owner on Mar 10, 2023. It is now read-only.

Commit 27eb84d

Browse files
Waterdripsalexellis
authored andcommitted
Don't error if ECR Repository exists already
We were returning an error if the ECR repo already exists. This shouldnt give an error because it's not a failure. If the repo doesn't exist then we create it, if it exists then that's fine. Tested by deploying an ECR backed OFC installation, first time round it creates the new repo, then after that it's not throwing an error, only saying it already exists. Signed-off-by: Alistair Hey <[email protected]>
1 parent 90d3204 commit 27eb84d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

register-image/Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

register-image/handler.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package function
33
import (
44
"encoding/json"
55
"fmt"
6+
"github.com/aws/aws-sdk-go/aws/awserr"
67
"log"
78
"os"
89
"strings"
@@ -68,9 +69,14 @@ func Handle(req []byte) string {
6869
output, err := client.CreateRepository(&repoReq)
6970

7071
if err != nil {
71-
log.Printf("CreateRepository error: %s\n", err.Error())
72-
os.Exit(1)
72+
if aerr, ok := err.(awserr.Error); ok {
73+
if aerr.Code() != ecr.ErrCodeRepositoryAlreadyExistsException {
74+
log.Printf("CreateRepository error: %s\n", err.Error())
75+
os.Exit(1)
76+
}
77+
}
78+
return fmt.Sprintf("Repo Exists: %s", *repoReq.RepositoryName)
7379
}
7480

75-
return fmt.Sprintf("Created repo: %s\n", output.String())
81+
return fmt.Sprintf("Created the repo: %s", output.String())
7682
}

0 commit comments

Comments
 (0)