@@ -46,6 +46,10 @@ const (
46
46
GCEAPIVersionV1 GCEAPIVersion = "v1"
47
47
// Alpha key type
48
48
GCEAPIVersionBeta GCEAPIVersion = "beta"
49
+ // Timeout for checking on an operation
50
+ OpTimeout = 2 * time .Minute
51
+ // Time interval for checking on an operation
52
+ OpInterval = 3 * time .Second
49
53
)
50
54
51
55
type GCECompute interface {
@@ -611,22 +615,24 @@ func (cloud *CloudProvider) AttachDisk(ctx context.Context, volKey *meta.Key, re
611
615
if err != nil {
612
616
return fmt .Errorf ("failed cloud service attach disk call: %v" , err )
613
617
}
618
+ klog .V (5 ).Infof ("Attaching disk %s operation id is %s" , volKey , op .Name )
614
619
err = cloud .waitForZonalOp (ctx , op .Name , instanceZone )
615
620
if err != nil {
616
- return fmt .Errorf ("failed when waiting for zonal op: %v" , err )
621
+ return fmt .Errorf ("failed when waiting for zonal op %s on attaching volume %v : %v" , op . Name , volKey , err )
617
622
}
618
623
return nil
619
624
}
620
625
621
626
func (cloud * CloudProvider ) DetachDisk (ctx context.Context , deviceName , instanceZone , instanceName string ) error {
622
- klog .V (5 ).Infof ("Detaching disk %v from %v" , deviceName , instanceName )
627
+ klog .V (5 ).Infof ("Detaching disk %s from %v" , deviceName , instanceName )
623
628
op , err := cloud .service .Instances .DetachDisk (cloud .project , instanceZone , instanceName , deviceName ).Context (ctx ).Do ()
624
629
if err != nil {
625
630
return err
626
631
}
632
+ klog .V (5 ).Infof ("Detaching disk %s operation id is %s" , deviceName , op .Name )
627
633
err = cloud .waitForZonalOp (ctx , op .Name , instanceZone )
628
634
if err != nil {
629
- return err
635
+ return fmt . Errorf ( "failed when waiting for zonal op %s on detaching volume %s: %v" , op . Name , deviceName , err )
630
636
}
631
637
return nil
632
638
}
@@ -681,7 +687,7 @@ func (cloud *CloudProvider) waitForZonalOp(ctx context.Context, opName string, z
681
687
// The v1 API can query for v1, alpha, or beta operations.
682
688
svc := cloud .service
683
689
project := cloud .project
684
- return wait .Poll (3 * time . Second , 5 * time . Minute , func () (bool , error ) {
690
+ return wait .Poll (OpInterval , OpTimeout , func () (bool , error ) {
685
691
pollOp , err := svc .ZoneOperations .Get (project , zone , opName ).Context (ctx ).Do ()
686
692
if err != nil {
687
693
klog .Errorf ("WaitForOp(op: %s, zone: %#v) failed to poll the operation" , opName , zone )
@@ -743,7 +749,10 @@ func (cloud *CloudProvider) WaitForAttach(ctx context.Context, volKey *meta.Key,
743
749
}
744
750
745
751
func opIsDone (op * computev1.Operation ) (bool , error ) {
746
- if op == nil || op .Status != operationStatusDone {
752
+ if op == nil {
753
+ return true , fmt .Errorf ("operation is nil" )
754
+ }
755
+ if op .Status != operationStatusDone {
747
756
return false , nil
748
757
}
749
758
if op .Error != nil && len (op .Error .Errors ) > 0 && op .Error .Errors [0 ] != nil {
0 commit comments