Skip to content

Commit

Permalink
Merge pull request #1719 from reddit/fix-instance-profile-deletion
Browse files Browse the repository at this point in the history
Skip error if role no longer exists in instance profile deletion
  • Loading branch information
Christopher Haar authored Apr 7, 2023
2 parents a679f94 + 9b616a1 commit 699f815
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/controller/iam/instanceprofile/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package instanceprofile
import (
"context"

"github.com/aws/aws-sdk-go/aws/awserr"
svcsdk "github.com/aws/aws-sdk-go/service/iam"
svcsdkapi "github.com/aws/aws-sdk-go/service/iam/iamiface"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -114,5 +115,12 @@ func (u *updater) preDelete(ctx context.Context, cr *svcapitypes.InstanceProfile
}

_, err := u.client.RemoveRoleFromInstanceProfileWithContext(ctx, input)
if awsErr, ok := err.(awserr.Error); ok {
// If the role no longer exists, then we have already deleted the role from the instance profile.
if awsErr.Code() == svcsdk.ErrCodeNoSuchEntityException {
return false, nil
}
}

return false, err
}

0 comments on commit 699f815

Please sign in to comment.