Skip to content

Commit 26a928a

Browse files
authored
Merge pull request #4078 from Skarlso/fix-error-checking-in-eventually
chore(ref): fix error checking in eventually
2 parents 6cbddb8 + 91c7874 commit 26a928a

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

test/e2e/shared/aws.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -475,23 +475,30 @@ func deleteResourcesInCloudFormation(prov client.ConfigProvider, t *cfn_bootstra
475475
if tayp == configservice.ResourceTypeAwsIamRole {
476476
role := val.(*cfn_iam.Role)
477477
By(fmt.Sprintf("cleanup for role with name '%s'", role.RoleName))
478+
// added repeat to not keep flooding the logs.
479+
repeat := false
478480
Eventually(func(gomega Gomega) bool {
479481
_, err := iamSvc.DeleteRole(&iam.DeleteRoleInput{RoleName: aws.String(role.RoleName)})
480-
if err != nil {
481-
By(fmt.Sprintf("failed to delete role '%s'; reason: %s", role.RoleName, err.Error()))
482+
if err != nil && !repeat {
483+
By(fmt.Sprintf("failed to delete role '%s'; reason: %+v", role.RoleName, err))
484+
repeat = true
482485
}
483-
return awserrors.IsNotFound(err) || err == nil
486+
code, ok := awserrors.Code(err)
487+
return err == nil || (ok && code == iam.ErrCodeNoSuchEntityException)
484488
}, 5*time.Minute, 5*time.Second).Should(BeTrue())
485489
}
486490
if val.AWSCloudFormationType() == "AWS::IAM::InstanceProfile" {
487491
profile := val.(*cfn_iam.InstanceProfile)
488492
By(fmt.Sprintf("cleanup for profile with name '%s'", profile.InstanceProfileName))
493+
repeat := false
489494
Eventually(func(gomega Gomega) bool {
490495
_, err := iamSvc.DeleteInstanceProfile(&iam.DeleteInstanceProfileInput{InstanceProfileName: aws.String(profile.InstanceProfileName)})
491-
if err != nil {
492-
By(fmt.Sprintf("failed to delete role '%s'; reason: %s", profile.InstanceProfileName, err.Error()))
496+
if err != nil && !repeat {
497+
By(fmt.Sprintf("failed to delete role '%s'; reason: %+v", profile.InstanceProfileName, err))
498+
repeat = true
493499
}
494-
return awserrors.IsNotFound(err) || err == nil
500+
code, ok := awserrors.Code(err)
501+
return err == nil || (ok && code == iam.ErrCodeNoSuchEntityException)
495502
}, 5*time.Minute, 5*time.Second).Should(BeTrue())
496503
}
497504
if val.AWSCloudFormationType() == "AWS::IAM::ManagedPolicy" {
@@ -502,12 +509,15 @@ func deleteResourcesInCloudFormation(prov client.ConfigProvider, t *cfn_bootstra
502509
for _, p := range policies.Policies {
503510
if aws.StringValue(p.PolicyName) == policy.ManagedPolicyName {
504511
By(fmt.Sprintf("cleanup for policy '%s'", p.String()))
512+
repeat := false
505513
Eventually(func(gomega Gomega) bool {
506514
_, err := iamSvc.DeletePolicy(&iam.DeletePolicyInput{PolicyArn: p.Arn})
507-
if err != nil {
508-
By(fmt.Sprintf("failed to delete policy '%s'; reason: %s", policy.Description, err.Error()))
515+
if err != nil && !repeat {
516+
By(fmt.Sprintf("failed to delete policy '%s'; reason: %+v", policy.Description, err))
517+
repeat = true
509518
}
510-
return awserrors.IsNotFound(err) || err == nil
519+
code, ok := awserrors.Code(err)
520+
return err == nil || (ok && code == iam.ErrCodeNoSuchEntityException)
511521
}, 5*time.Minute, 5*time.Second).Should(BeTrue())
512522
// TODO: why is there a break here? Don't we want to clean up everything?
513523
break

0 commit comments

Comments
 (0)