func()

in pkg/csi/controller.go [434:471]


func (a *attacher) attachDisk(ctx context.Context, volume, nodeName string) error {
	vol, err := parseVolumeHandle(volume)
	if err != nil {
		return err
	}

	attach := &compute.AttachedDisk{
		DeviceName: vol.name,
		Source:     sourceFromVolumeHandle(volume),
		Mode:       "READ_WRITE",
		Type:       "PERSISTENT",
	}
	op, err := a.computeSvc.Instances.AttachDisk(vol.project, vol.zone, nodeName, attach).Context(ctx).Do()
	if err != nil {
		return err
	}
	err = wait.PollUntilContextTimeout(ctx, 5*time.Second, 2*time.Minute, true, func(ctx context.Context) (bool, error) {
		pollOp, err := a.computeSvc.ZoneOperations.Get(vol.project, vol.zone, op.Name).Context(ctx).Do()
		if err != nil {
			return false, err
		}
		if pollOp == nil || pollOp.Status != "DONE" {
			return false, nil // retry
		}
		if pollOp.Error != nil {
			errs := []string{}
			for _, e := range pollOp.Error.Errors {
				errs = append(errs, fmt.Sprintf("%v", e))
			}
			return false, fmt.Errorf("error waiting for attach to %s: %v", nodeName, errs)
		}
		return true, nil
	})
	if err != nil {
		return fmt.Errorf("could not attach %s to %s: %w", volume, nodeName, err)
	}
	return nil
}