Skip to content

Commit 3e89e05

Browse files
committed
1. use flowcontrol backoff lib for publish/unpublish backoff
2. backoff on resource exhausted error
1 parent 11e2389 commit 3e89e05

File tree

9 files changed

+319
-324
lines changed

9 files changed

+319
-324
lines changed

pkg/gce-cloud-provider/compute/fake-gce.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package gcecloudprovider
1717
import (
1818
"context"
1919
"fmt"
20+
"net/http"
2021
"strconv"
2122
"strings"
2223

@@ -419,8 +420,9 @@ func (cloud *FakeCloudProvider) UpdateDiskStatus(s string) {
419420
}
420421

421422
type Signal struct {
422-
ReportError bool
423-
ReportRunning bool
423+
ReportError bool
424+
ReportRunning bool
425+
ReportTooManyRequestsError bool
424426
}
425427

426428
type FakeBlockingCloudProvider struct {
@@ -446,6 +448,9 @@ func (cloud *FakeBlockingCloudProvider) WaitForZonalOp(ctx context.Context, proj
446448
if val.ReportError {
447449
return fmt.Errorf("force mock error of zonal op %s", opName)
448450
}
451+
if val.ReportTooManyRequestsError {
452+
return tooManyRequestsError()
453+
}
449454
return nil
450455
}
451456

@@ -483,6 +488,12 @@ func invalidError() *googleapi.Error {
483488
}
484489
}
485490

491+
func tooManyRequestsError() *googleapi.Error {
492+
return &googleapi.Error{
493+
Code: http.StatusTooManyRequests,
494+
}
495+
}
496+
486497
func (cloud *FakeCloudProvider) StartAttachDiskOp(ctx context.Context, volKey *meta.Key, readWrite, diskType, project, location, instanceName string) (*computev1.Operation, error) {
487498
source := cloud.GetDiskSourceURI(project, volKey)
488499
attachedDiskV1 := &computev1.AttachedDisk{

pkg/gce-cloud-provider/compute/gce-compute.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ func (cloud *CloudProvider) WaitForAttach(ctx context.Context, project string, v
716716
klog.V(6).Infof("Polling for attach of disk %v to instance %v to complete for %v", volKey.Name, instanceName, time.Since(start))
717717
disk, err := cloud.GetDisk(ctx, project, volKey, GCEAPIVersionV1)
718718
if err != nil {
719-
return false, fmt.Errorf("GetDisk failed to get disk: %v", err)
719+
return false, err
720720
}
721721

722722
if disk == nil {
@@ -953,7 +953,7 @@ func (cloud *CloudProvider) CheckZonalOpDoneStatus(ctx context.Context, project,
953953
lastKnownOp, err := cloud.service.ZoneOperations.Get(project, location, opId).Context(ctx).Do()
954954
if err != nil {
955955
if !IsGCENotFoundError(err) {
956-
return false, fmt.Errorf("failed to get operation %s: %v", opId, err)
956+
return false, err
957957
}
958958
return true, nil
959959
}

pkg/gce-cloud-provider/compute/gce.go

+9
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,12 @@ func IsGCENotFoundError(err error) bool {
263263
func IsGCEInvalidError(err error) bool {
264264
return IsGCEError(err, "invalid")
265265
}
266+
267+
// IsGCENotFoundError returns true if the error is a googleapi.Error with
268+
// resource exhausted error code.
269+
func IsTooManyRequestError(err error) bool {
270+
if apierr, ok := err.(*googleapi.Error); ok && apierr.Code == http.StatusTooManyRequests {
271+
return true
272+
}
273+
return false
274+
}

0 commit comments

Comments
 (0)