Skip to content

Commit 65f26df

Browse files
modular-magiciandanawillow
authored andcommitted
retry on resourceNotReady (#4433)
Signed-off-by: Modular Magician <[email protected]>
1 parent 60da651 commit 65f26df

5 files changed

+34
-0
lines changed

google/common_operation.go

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ type Waiter interface {
1818
// if the operation has no current error.
1919
Error() error
2020

21+
// IsRetryable returns whether a given error should be retried.
22+
IsRetryable(error) bool
23+
2124
// SetOp sets the operation we're waiting on in a Waiter struct so that it
2225
// can be used in other methods.
2326
SetOp(interface{}) error
@@ -59,6 +62,10 @@ func (w *CommonOperationWaiter) Error() error {
5962
return nil
6063
}
6164

65+
func (w *CommonOperationWaiter) IsRetryable(error) bool {
66+
return false
67+
}
68+
6269
func (w *CommonOperationWaiter) SetOp(op interface{}) error {
6370
if err := Convert(op, &w.Op); err != nil {
6471
return err
@@ -110,6 +117,10 @@ func CommonRefreshFunc(w Waiter) resource.StateRefreshFunc {
110117
}
111118

112119
if err = w.Error(); err != nil {
120+
if w.IsRetryable(err) {
121+
log.Printf("[DEBUG] Retrying operation GET based on retryable err: %s", err)
122+
return op, w.State(), nil
123+
}
113124
return nil, "", err
114125
}
115126

google/compute_operation.go

+11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ func (w *ComputeOperationWaiter) Error() error {
2929
return nil
3030
}
3131

32+
func (w *ComputeOperationWaiter) IsRetryable(err error) bool {
33+
if oe, ok := err.(ComputeOperationError); ok {
34+
for _, e := range oe.Errors {
35+
if e.Code == "RESOURCE_NOT_READY" {
36+
return true
37+
}
38+
}
39+
}
40+
return false
41+
}
42+
3243
func (w *ComputeOperationWaiter) SetOp(op interface{}) error {
3344
var ok bool
3445
w.Op, ok = op.(*compute.Operation)

google/container_operation.go

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func (w *ContainerOperationWaiter) Error() error {
4141
return nil
4242
}
4343

44+
func (w *ContainerOperationWaiter) IsRetryable(error) bool {
45+
return false
46+
}
47+
4448
func (w *ContainerOperationWaiter) SetOp(op interface{}) error {
4549
var ok bool
4650
w.Op, ok = op.(*container.Operation)

google/dataproc_job_operation.go

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ func (w *DataprocJobOperationWaiter) Error() error {
2828
return nil
2929
}
3030

31+
func (w *DataprocJobOperationWaiter) IsRetryable(error) bool {
32+
return false
33+
}
34+
3135
func (w *DataprocJobOperationWaiter) SetOp(job interface{}) error {
3236
// The "operation" is just the job. Instead of holding onto the whole job
3337
// object, we only care about the state, which gets set in QueryOp, so this

google/sqladmin_operation.go

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ func (w *SqlAdminOperationWaiter) Error() error {
3333
return nil
3434
}
3535

36+
func (w *SqlAdminOperationWaiter) IsRetryable(error) bool {
37+
return false
38+
}
39+
3640
func (w *SqlAdminOperationWaiter) SetOp(op interface{}) error {
3741
if op == nil {
3842
// Starting as a log statement, this may be a useful error in the future

0 commit comments

Comments
 (0)