Skip to content

Commit

Permalink
fix: correctly empty repos when deleting app regional resources (#5617)
Browse files Browse the repository at this point in the history
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
  • Loading branch information
Lou1415926 authored Jan 19, 2024
1 parent 19f6fe9 commit 295049a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions internal/pkg/deploy/cloudformation/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,12 @@ func (cf CloudFormation) cleanUpRegionalResources(app *config.Application, regio
if err := s3.EmptyBucket(resources.S3Bucket); err != nil {
return err
}
ecrRepoName := func(app, workload string) string {
return fmt.Sprintf("%s/%s", app, workload)
}
ecr := cf.regionalECRClient(region)
for repo := range resources.RepositoryURLs {
if err := ecr.ClearRepository(repo); err != nil {
for svcName := range resources.RepositoryURLs {
if err := ecr.ClearRepository(ecrRepoName(app.Name, svcName)); err != nil {
return err
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/deploy/cloudformation/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ func TestCloudFormation_RemoveEnvFromApp(t *testing.T) {
}, nil)
regionalCfn.EXPECT().Describe("some-stack").Return(mockValidAppResourceStack(), nil)
s3.EXPECT().EmptyBucket("tests3-bucket-us-west-2").Return(nil)
ecr.EXPECT().ClearRepository("phonetool-svc").Return(nil)
ecr.EXPECT().ClearRepository("phonetool/phonetool-svc").Return(nil)
appStackSet.EXPECT().DeleteInstance("phonetool-infrastructure", "1234", "us-west-2").Return("123", nil)
appStackSet.EXPECT().WaitForOperation("phonetool-infrastructure", "123").Return(nil)
cfn.EXPECT().Describe(stack.NameForAppStack("phonetool")).Return(&cloudformation.StackDescription{
Expand Down Expand Up @@ -1432,7 +1432,7 @@ func TestCloudFormation_RemoveEnvFromApp(t *testing.T) {
}, nil)
regionalCfn.EXPECT().Describe("some-stack").Return(mockValidAppResourceStack(), nil)
s3.EXPECT().EmptyBucket("tests3-bucket-us-west-2").Return(nil)
ecr.EXPECT().ClearRepository("phonetool-svc").Return(nil)
ecr.EXPECT().ClearRepository("phonetool/phonetool-svc").Return(nil)
appStackSet.EXPECT().DeleteInstance("phonetool-infrastructure", "1234", "us-west-2").Return("123", nil)
appStackSet.EXPECT().WaitForOperation("phonetool-infrastructure", "123").Return(nil)
cfn.EXPECT().Describe(gomock.Any()).Times(0)
Expand Down Expand Up @@ -1583,7 +1583,7 @@ func TestCloudFormation_RemoveEnvFromApp(t *testing.T) {
}, nil)
regionalCfn.EXPECT().Describe("some-stack").Return(mockValidAppResourceStack(), nil)
s3.EXPECT().EmptyBucket("tests3-bucket-us-west-2").Return(nil)
ecr.EXPECT().ClearRepository("phonetool-svc").Return(nil)
ecr.EXPECT().ClearRepository("phonetool/phonetool-svc").Return(nil)
// Delete stackset instance
appStackSet.EXPECT().DeleteInstance("phonetool-infrastructure", "1234", "us-west-2").Return("", errors.New("some error"))
appStackSet.EXPECT().WaitForOperation(gomock.Any(), gomock.Any()).Times(0)
Expand Down Expand Up @@ -1652,7 +1652,7 @@ func TestCloudFormation_RemoveEnvFromApp(t *testing.T) {
}, nil)
regionalCfn.EXPECT().Describe("some-stack").Return(mockValidAppResourceStack(), nil)
s3.EXPECT().EmptyBucket("tests3-bucket-us-west-2").Return(nil)
ecr.EXPECT().ClearRepository("phonetool-svc").Return(nil)
ecr.EXPECT().ClearRepository("phonetool/phonetool-svc").Return(nil)
appStackSet.EXPECT().DeleteInstance("phonetool-infrastructure", "1234", "us-west-2").Return("123", nil)
appStackSet.EXPECT().WaitForOperation("phonetool-infrastructure", "123").Return(nil)
cfn.EXPECT().Describe(stack.NameForAppStack("phonetool")).Return(&cloudformation.StackDescription{
Expand Down

0 comments on commit 295049a

Please sign in to comment.