-
Notifications
You must be signed in to change notification settings - Fork 292
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
Support Spaces Key API #1309
Support Spaces Key API #1309
Conversation
8c45dad
to
bb5af54
Compare
186198b
to
ad1edb3
Compare
ad1edb3
to
025fc5c
Compare
log.Printf("[DEBUG] Creating new Spaces key") | ||
key, _, err = client.SpacesKeys.Create(ctx, req) | ||
if err != nil { | ||
return retry.RetryableError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing some testing, I realized that that this was retrying a 403 Forbidden repeatedly. You'll probably want to inspect this error before returning a RetryableError
.
By default, the godo
client is configured to retry 500-level errors. So retry.RetryContext
is generally only needed if there are specific cases you are trying to work around.
For example:
terraform-provider-digitalocean/digitalocean/project/resource_project.go
Lines 287 to 297 in 8473e52
// Moving resources is async and projects can not be deleted till empty. Retries may be required. | |
err := retry.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *retry.RetryError { | |
_, err := client.Projects.Delete(context.Background(), projectID) | |
if err != nil { | |
if util.IsDigitalOceanError(err, http.StatusPreconditionFailed, "cannot delete a project with resources") { | |
log.Printf("[DEBUG] Received %s, retrying project deletion", err.Error()) | |
return retry.RetryableError(err) | |
} | |
return retry.NonRetryableError(err) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put in a few places where retries shouldn't happen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What scenario are you thinking that we'd need to retry a create request for? For example, sometimes we have to retry a request if we know we have to wait for another resource to be in a ready state (waiting on new database to accept connections, or a new droplet to be accessible etc.) or if we want a resource to be a in a certain state before we can use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of the bucket keys related scenarios are async in that sense. We don't have to wait for anything to be in a specific state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok sweet, we're good to remove it then.
279d6d4
to
e7b469c
Compare
cc7d2d9
to
8e33402
Compare
9b7df31
to
0e55d8a
Compare
0e55d8a
to
a2aca42
Compare
Co-authored-by: danaelhe <[email protected]>
Co-authored-by: danaelhe <[email protected]>
e8d46c4
to
38e1ea8
Compare
err := retry.RetryContext(ctx, 5*time.Minute, func() *retry.RetryError { | ||
log.Printf("[DEBUG] Deleting Spaces key: %s", d.Id()) | ||
_, err := client.SpacesKeys.Delete(ctx, d.Id()) | ||
if err != nil { | ||
if util.IsDigitalOceanError(err, http.StatusInternalServerError, "") || util.IsDigitalOceanError(err, http.StatusPreconditionFailed, "") { | ||
return retry.NonRetryableError(err) | ||
} | ||
return retry.RetryableError( | ||
fmt.Errorf("[WARN] Error deleting Spaces key: %s, retrying: %s", d.Id(), err)) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return diag.Errorf("Error deleting Spaces key: %s", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err := retry.RetryContext(ctx, 5*time.Minute, func() *retry.RetryError { | |
log.Printf("[DEBUG] Deleting Spaces key: %s", d.Id()) | |
_, err := client.SpacesKeys.Delete(ctx, d.Id()) | |
if err != nil { | |
if util.IsDigitalOceanError(err, http.StatusInternalServerError, "") || util.IsDigitalOceanError(err, http.StatusPreconditionFailed, "") { | |
return retry.NonRetryableError(err) | |
} | |
return retry.RetryableError( | |
fmt.Errorf("[WARN] Error deleting Spaces key: %s, retrying: %s", d.Id(), err)) | |
} | |
return nil | |
}) | |
if err != nil { | |
return diag.Errorf("Error deleting Spaces key: %s", err) | |
} | |
log.Printf("[DEBUG] Deleting Spaces key: %s", d.Id()) | |
_, err := client.SpacesKeys.Delete(ctx, d.Id()) | |
if err != nil { | |
return diag.Errorf("Error deleting Spaces key: %s", err) | |
} |
Adds support for Spaces Key API based on digitalocean/openapi#958