func WaitForOperationInProgress()

in pkg/operations/operations.go [113:137]


func WaitForOperationInProgress(ctx context.Context, f func(ctx context.Context) error, wait func(ctx context.Context, op string) error) error {
	err := f(ctx)
	if err == nil {
		return nil
	}

	op := ObtainID(err)
	if op == "" {
		return err
	}
	if !strings.Contains(err.Error(), fmt.Sprintf("Operation %s is currently", op)) {
		// Match format of errors returned by the GKE API.
		return err
	}

	log.Infof("Operation %s is in progress; wait for operation to complete: %v", op, err)

	if err := wait(ctx, op); err != nil {
		return err
	}

	log.Infof("Operation %s is complete; retrying. Retry due to: %v", op, err)

	return f(ctx)
}