Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry for storage bucket 412 #2011

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3434.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
storage: Added retries for `google_storage_bucket_iam_*` on 412 (precondition not met) errors for eventually consistent bucket creation.
```
7 changes: 7 additions & 0 deletions google-beta/error_retry_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,10 @@ func isNotFoundRetryableError(opType string) RetryErrorPredicateFunc {
return false, ""
}
}

func isStoragePreconditionError(err error) (bool, string) {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 412 {
return true, fmt.Sprintf("Retry on storage precondition not met")
}
return false, ""
}
4 changes: 2 additions & 2 deletions google-beta/iam_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (u *StorageBucketIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.
return nil, err
}

policy, err := sendRequest(u.Config, "GET", "", url, obj)
policy, err := sendRequest(u.Config, "GET", "", url, obj, isStoragePreconditionError)
if err != nil {
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
Expand All @@ -129,7 +129,7 @@ func (u *StorageBucketIamUpdater) SetResourceIamPolicy(policy *cloudresourcemana
return err
}

_, err = sendRequestWithTimeout(u.Config, "PUT", "", url, obj, u.d.Timeout(schema.TimeoutCreate))
_, err = sendRequestWithTimeout(u.Config, "PUT", "", url, obj, u.d.Timeout(schema.TimeoutCreate), isStoragePreconditionError)
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
Expand Down