From 0fc0c1196704d29c25e37ce77cb0ba710402e8d3 Mon Sep 17 00:00:00 2001 From: Anurag Mittal Date: Fri, 13 Dec 2024 12:09:23 +0100 Subject: [PATCH] COSI-40: ignore-failure-if-access-key-deleted-in-flight --- pkg/clients/iam/iam_client.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/clients/iam/iam_client.go b/pkg/clients/iam/iam_client.go index 9fcdb391..ace8f802 100644 --- a/pkg/clients/iam/iam_client.go +++ b/pkg/clients/iam/iam_client.go @@ -209,13 +209,17 @@ func (client *IAMClient) DeleteAllAccessKeys(ctx context.Context, userName strin if err != nil { return fmt.Errorf("failed to list access keys for IAM user %s: %w", userName, err) } - + var noSuchEntityErr *types.NoSuchEntityException for _, key := range listKeysOutput.AccessKeyMetadata { _, err := client.IAMService.DeleteAccessKey(ctx, &iam.DeleteAccessKeyInput{ UserName: &userName, AccessKeyId: key.AccessKeyId, }) if err != nil { + if errors.As(err, &noSuchEntityErr) { + klog.V(5).InfoS("Access key does not exist, skipping deletion", "user", userName, "accessKeyId", *key.AccessKeyId) + continue + } return fmt.Errorf("failed to delete access key %s for IAM user %s: %w", *key.AccessKeyId, userName, err) } klog.V(5).InfoS("Successfully deleted access key", "user", userName, "accessKeyId", *key.AccessKeyId) @@ -230,7 +234,7 @@ func (client *IAMClient) DeleteUser(ctx context.Context, userName string) error var noSuchEntityErr *types.NoSuchEntityException if errors.As(err, &noSuchEntityErr) { klog.InfoS("IAM user does not exist, skipping deletion", "user", userName) - return nil // User doesn't exist, nothing to delete + return nil } return fmt.Errorf("failed to delete IAM user %s: %w", userName, err) }