Skip to content

Commit a402dd0

Browse files
rcohenmacodycushing
authored andcommitted
undoing retry logic in terraform provider as it has been moved to the Go SDK (#162)
1 parent 1e461a7 commit a402dd0

File tree

1 file changed

+0
-50
lines changed

1 file changed

+0
-50
lines changed

crud/helpers.go

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"errors"
77
"log"
88
"reflect"
9-
"regexp"
109
"strconv"
1110
"strings"
1211
"time"
@@ -18,7 +17,6 @@ import (
1817
)
1918

2019
var (
21-
MaxRetries uint = 6
2220
FiveMinutes time.Duration = 5 * time.Minute
2321
TwoHours time.Duration = 120 * time.Minute
2422
DefaultTimeout = &schema.ResourceTimeout{
@@ -173,30 +171,8 @@ func LoadBalancerWaitForWorkRequest(client client.BareMetalClient, d *schema.Res
173171
return nil
174172
}
175173

176-
func exponentialBackoffSleep(retryNum uint) {
177-
secondsToSleep := 1 << retryNum
178-
log.Printf("[DEBUG] Got a retriable error. Waiting %d seconds and trying again...", secondsToSleep)
179-
time.Sleep(time.Duration(secondsToSleep) * time.Second)
180-
}
181-
182-
func isRetriableError(error string) bool {
183-
//all errors are retriable except 400, 401, 412, and 409 with code InvalidatedRetryToken
184-
lowerCaseError := strings.ToLower(error)
185-
statusMatch, _ := regexp.MatchString("status\\s*:\\s*4(0[01]|12)", lowerCaseError)
186-
codeMatch, _ := regexp.MatchString("code\\s*:\\s*invalidatedretrytoken", lowerCaseError)
187-
return !statusMatch && !codeMatch
188-
}
189-
190174
func CreateResource(d *schema.ResourceData, sync ResourceCreator) (e error) {
191-
return createResourceWithRetry(d, sync, 1)
192-
}
193-
194-
func createResourceWithRetry(d *schema.ResourceData, sync ResourceCreator, retryNum uint) (e error) {
195175
if e = sync.Create(); e != nil {
196-
if isRetriableError(e.Error()) && retryNum <= MaxRetries {
197-
exponentialBackoffSleep(retryNum)
198-
e = createResourceWithRetry(d, sync, retryNum+1)
199-
}
200176
return e
201177
}
202178

@@ -218,19 +194,9 @@ func createResourceWithRetry(d *schema.ResourceData, sync ResourceCreator, retry
218194
}
219195

220196
func ReadResource(sync ResourceReader) (e error) {
221-
return readResourceWithRetry(sync, 1)
222-
}
223-
224-
func readResourceWithRetry(sync ResourceReader, retryNum uint) (e error) {
225197
if e = sync.Get(); e != nil {
226198
log.Printf("ERROR IN GET: %v\n", e.Error())
227199
handleMissingResourceError(sync, &e)
228-
if e != nil {
229-
if isRetriableError(e.Error()) && retryNum <= MaxRetries {
230-
exponentialBackoffSleep(retryNum)
231-
e = readResourceWithRetry(sync, retryNum+1)
232-
}
233-
}
234200
return
235201
}
236202

@@ -251,16 +217,8 @@ func readResourceWithRetry(sync ResourceReader, retryNum uint) (e error) {
251217
}
252218

253219
func UpdateResource(d *schema.ResourceData, sync ResourceUpdater) (e error) {
254-
return updateResourceWithRetry(d, sync, 1)
255-
}
256-
257-
func updateResourceWithRetry(d *schema.ResourceData, sync ResourceUpdater, retryNum uint) (e error) {
258220
d.Partial(true)
259221
if e = sync.Update(); e != nil {
260-
if isRetriableError(e.Error()) && retryNum <= MaxRetries {
261-
exponentialBackoffSleep(retryNum)
262-
e = updateResourceWithRetry(d, sync, retryNum+1)
263-
}
264222
return
265223
}
266224
d.Partial(false)
@@ -274,17 +232,9 @@ func updateResourceWithRetry(d *schema.ResourceData, sync ResourceUpdater, retry
274232
// () -> Pending -> Deleted.
275233
// Finally, sets the ResourceData state to empty.
276234
func DeleteResource(d *schema.ResourceData, sync ResourceDeleter) (e error) {
277-
return deleteResourceWithRetry(d, sync, 1)
278-
}
279-
280-
func deleteResourceWithRetry(d *schema.ResourceData, sync ResourceDeleter, retryNum uint) (e error) {
281235
if e = sync.Delete(); e != nil {
282236
handleMissingResourceError(sync, &e)
283237
if e != nil {
284-
if isRetriableError(e.Error()) && retryNum <= MaxRetries {
285-
exponentialBackoffSleep(retryNum)
286-
e = deleteResourceWithRetry(d, sync, retryNum+1)
287-
}
288238
return
289239
}
290240
}

0 commit comments

Comments
 (0)