in pkg/csi/node.go [39:86]
func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
if len(req.GetTargetPath()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Target path missing in request")
}
if d.vol == nil {
var err error
if d.vol, err = createCacheVolume(ctx, d.client, d.nodeId, d.volumeTypeMap); err != nil {
if errors.Is(err, &common.VolumePendingError{}) {
return nil, status.Errorf(codes.Aborted, "local volume not ready: %v", err)
}
return nil, status.Error(codes.Internal, fmt.Sprintf("local volume creation failed: %v", err))
}
}
targetPath := req.GetTargetPath()
notMnt, err := mount.New("").IsLikelyNotMountPoint(targetPath)
if err != nil {
if os.IsNotExist(err) {
if err = os.MkdirAll(targetPath, 0750); err != nil {
return nil, status.Errorf(codes.Internal, "Target mount point creation failed: %v", err)
}
notMnt = true
} else {
return nil, status.Errorf(codes.Internal, "Target mount point exists in bad state: %v", err)
}
}
if !notMnt {
return &csi.NodePublishVolumeResponse{}, nil
}
readOnly := req.GetReadonly()
mount_options := []string{"bind"}
if readOnly {
mount_options = append(mount_options, "ro")
}
mounter := &mount.SafeFormatAndMount{
Interface: mount.New(""),
Exec: exec.New(),
}
if err := mounter.Interface.Mount(d.vol.Path(), targetPath, "", mount_options); err != nil {
return nil, err
}
klog.Infof("Mounted %s to %s", d.vol.Path(), targetPath)
return &csi.NodePublishVolumeResponse{}, nil
}