github.com/openshift/installer@v1.4.17/pkg/infrastructure/gcp/clusterapi/operation.go (about) 1 package clusterapi 2 3 import ( 4 "context" 5 "fmt" 6 "time" 7 8 "google.golang.org/api/compute/v1" 9 ) 10 11 // WaitForOperationGlobal will attempt to wait for a operation to complete where the operational 12 // resource is globally scoped. 13 func WaitForOperationGlobal(ctx context.Context, projectID string, operation *compute.Operation) error { 14 ctx, cancel := context.WithTimeout(ctx, time.Minute*1) 15 defer cancel() 16 17 service, err := NewComputeService() 18 if err != nil { 19 return err 20 } 21 22 g := compute.NewGlobalOperationsService(service) 23 if _, err := g.Wait(projectID, operation.Name).Context(ctx).Do(); err != nil { 24 return fmt.Errorf("failed to wait for regional operation: %w", err) 25 } 26 27 return nil 28 } 29 30 // WaitForOperationRegional will attempt to wait for a operation to complete where the operational 31 // resource is regionally scoped. 32 func WaitForOperationRegional(ctx context.Context, projectID, region string, operation *compute.Operation) error { 33 ctx, cancel := context.WithTimeout(ctx, time.Minute*1) 34 defer cancel() 35 36 service, err := NewComputeService() 37 if err != nil { 38 return err 39 } 40 41 r := compute.NewRegionOperationsService(service) 42 if _, err := r.Wait(projectID, region, operation.Name).Context(ctx).Do(); err != nil { 43 return fmt.Errorf("failed to wait for regional operation: %w", err) 44 } 45 46 return nil 47 }