예제 #1
0
def v3io_to_vol(name, remote="~/", access_key="", user="", secret=None):
    from os import environ
    from kubernetes import client

    access_key = access_key or environ.get("V3IO_ACCESS_KEY")
    opts = {"accessKey": access_key}

    remote = str(remote)

    if remote.startswith("~/"):
        user = environ.get("V3IO_USERNAME", user)
        if not user:
            raise mlrun.errors.MLRunInvalidArgumentError(
                'user name/env must be specified when using "~" in path')
        if remote == "~/":
            remote = "users/" + user
        else:
            remote = "users/" + user + remote[1:]
    if remote:
        container, subpath = split_path(remote)
        opts["container"] = container
        opts["subPath"] = subpath

    if secret:
        secret = {"name": secret}

    # vol = client.V1Volume(name=name, flex_volume=client.V1FlexVolumeSource('v3io/fuse', options=opts))
    vol = {
        "flexVolume":
        client.V1FlexVolumeSource("v3io/fuse", options=opts,
                                  secret_ref=secret),
        "name":
        name,
    }
    return vol
예제 #2
0
def v3io_to_vol(name, remote='~/', access_key='', user=''):
    from os import environ
    from kubernetes import client
    access_key = access_key or environ.get('V3IO_ACCESS_KEY')
    remote = str(remote)

    if remote.startswith('~/'):
        user = environ.get('V3IO_USERNAME', user)
        if not user:
            raise ValueError(
                'user name/env must be specified when using "~" in path')
        if remote == '~/':
            remote = 'users/' + user
        else:
            remote = 'users/' + user + remote[1:]
    container, subpath = split_path(remote)

    opts = {
        'accessKey': access_key,
        'container': container,
        'subPath': subpath
    }
    vol = client.V1Volume(name=name,
                          flex_volume=client.V1FlexVolumeSource('v3io/fuse',
                                                                options=opts))
    return vol
예제 #3
0
def make_pod_spec(app_id):

    pod_name = 'app-{app_id}-{uuid}'.format(app_id=app_id, uuid=uuid().hex[:8])
    args = [
        'bokeh', 'serve', '--port',
        str(BOKEH_PORT), '/s3/jubo-apps/{}'.format(app_id)
    ]
    s3_volume = client.V1Volume(
        name='s3',
        flex_volume=client.V1FlexVolumeSource(
            driver="informaticslab/s3-fuse-flex-volume",
            options={'readonly': "true"}))
    pod = client.V1Pod(
        metadata=client.V1ObjectMeta(
            name=pod_name,
            labels={MARK_AS_REAPABLE_LABEL: MARK_AS_REAPABLE_LABEL_VALUE}),
        spec=client.V1PodSpec(
            restart_policy='Never',
            containers=[
                client.V1Container(
                    name=pod_name,
                    image='informaticslab/singleuser-notebook:latest',
                    args=args,
                    ports=[
                        client.V1ContainerPort(container_port=BOKEH_PORT,
                                               name='bokeh')
                    ],
                    volume_mounts=[
                        client.V1VolumeMount(name='s3', mount_path='/s3')
                    ])
            ],
            volumes=[s3_volume]))
    return pod
예제 #4
0
    def _mount_v3io(task):
        from kubernetes import client as k8s_client
        from os import environ
        _access_key = access_key or environ.get('V3IO_ACCESS_KEY')
        _remote = remote

        if _remote.startswith('~/'):
            user = environ.get('V3IO_USERNAME', '')
            if not user:
                raise ValueError('user name/env must be specified when using "~" in path')
            if _remote == '~/':
                _remote = 'users/' + user
            else:
                _remote = 'users/' + user + _remote[1:]
        container, subpath = split_path(_remote)

        opts = {'accessKey': _access_key, 'container': container, 'subPath': subpath}
        vol = {'flexVolume': k8s_client.V1FlexVolumeSource('v3io/fuse', options=opts), 'name': name}

        task.add_volume(vol).add_volume_mount(k8s_client.V1VolumeMount(mount_path=mount_path, name=name))

        task = v3io_cred(access_key=access_key)(task)
        return (task)