예제 #1
0
def get_inference_service(namespace, name):
    inference_service = api.get_custom_rsrc(**versions.inference_service_gvk(),
                                            namespace=namespace, name=name)
    if request.args.get("logs", "false") == "true":
        # find the logs
        return api.success_response(
            "serviceLogs", get_inference_service_logs(inference_service)
        )

    return api.success_response("inferenceService", inference_service)
예제 #2
0
def delete_inference_service(inference_service, namespace):
    log.info("Deleting InferenceService %s/%s'", namespace, inference_service)
    gvk = versions.inference_service_gvk()
    api.delete_custom_rsrc(**gvk, name=inference_service, namespace=namespace)
    return api.success_response(
        "message", "InferenceService %s/%s successfully deleted." %
        (namespace, inference_service))
예제 #3
0
파일: post.py 프로젝트: zijianjoy/kubeflow
def post_pvc(namespace):
    body = request.get_json()
    log.info(f"Got body: {body}")

    notebook = helpers.load_param_yaml(
        utils.NOTEBOOK_TEMPLATE_YAML,
        name=body["name"],
        namespace=namespace,
        serviceAccount="default-editor",
    )

    defaults = utils.load_spawner_ui_config()

    form.set_notebook_image(notebook, body, defaults)
    form.set_notebook_image_pull_policy(notebook, body, defaults)
    form.set_server_type(notebook, body, defaults)
    form.set_notebook_cpu(notebook, body, defaults)
    form.set_notebook_memory(notebook, body, defaults)
    form.set_notebook_gpus(notebook, body, defaults)
    form.set_notebook_tolerations(notebook, body, defaults)
    form.set_notebook_affinity(notebook, body, defaults)
    form.set_notebook_configurations(notebook, body, defaults)

    # Workspace Volume
    workspace_vol = form.get_workspace_vol(body, defaults)
    if not body.get("noWorkspace", False) and workspace_vol["type"] == "New":
        # Create the PVC
        ws_pvc = utils.pvc_from_dict(workspace_vol, namespace)

        log.info("Creating Workspace Volume: %s", ws_pvc.to_dict())
        api.create_pvc(ws_pvc, namespace)

    if not body.get("noWorkspace", False) and workspace_vol["type"] != "None":
        form.add_notebook_volume(
            notebook,
            workspace_vol["name"],
            workspace_vol["name"],
            "/home/jovyan",
        )

    # Add the Data Volumes
    for vol in form.get_data_vols(body, defaults):
        if vol["type"] == "New":
            # Create the PVC
            dtvol_pvc = utils.pvc_from_dict(vol, namespace)

            log.info("Creating Data Volume: %s", dtvol_pvc)
            api.create_pvc(dtvol_pvc, namespace=namespace)

        form.add_notebook_volume(notebook, vol["name"], vol["name"],
                                 vol["path"])

    # shm
    form.set_notebook_shm(notebook, body, defaults)

    log.info("Creating Notebook: %s", notebook)
    api.create_notebook(notebook, namespace)

    return api.success_response("message", "Notebook created successfully.")
예제 #4
0
def post_inference_service(namespace):
    cr = request.get_json()

    gvk = versions.inference_service_gvk()
    api.create_custom_rsrc(**gvk, data=cr, namespace=namespace)

    return api.success_response("message",
                                "InferenceService successfully created.")
예제 #5
0
def get_pvcs(namespace):
    pvcs = api.list_pvcs(namespace).items
    data = [{
        "name": pvc.metadata.name,
        "size": pvc.spec.resources.requests["storage"],
        "mode": pvc.spec.access_modes[0]
    } for pvc in pvcs]

    return api.success_response("pvcs", data)
예제 #6
0
def get_tensorboards(namespace):

    tensorboards = api.list_custom_rsrc("tensorboard.kubeflow.org", "v1alpha1",
                                        "tensorboards", namespace)
    content = [
        utils.parse_tensorboard(tensorboard)
        for tensorboard in tensorboards["items"]
    ]

    return api.success_response("tensorboards", content)
예제 #7
0
파일: post.py 프로젝트: arllanos/kubeflow
def post_pvc(namespace):
    body = request.get_json()
    log.info("Received body: %s", body)

    pvc = form.pvc_from_dict(body, namespace)

    log.info("Creating PVC '%s'...", pvc)
    api.create_pvc(pvc, namespace)
    log.info("Successfully created PVC %s/%s", namespace, pvc.metadata.name)

    return api.success_response("message", "PVC created successfully.")
예제 #8
0
파일: post.py 프로젝트: arllanos/kubeflow
def post_viewer(namespace):
    body = request.get_json()
    log.info("Received body: %s", body)

    name = body["name"]
    viewer = rok_utils.load_pvcviewer_yaml_template(name=name,
                                                    namespace=namespace)

    log.info("Creating PVCViewer '%s'...", viewer)
    api.create_custom_rsrc(*rok_utils.PVCVIEWER, viewer, namespace)
    log.info("Successfully created PVCViewer %s/%s", namespace, name)

    return api.success_response("message", "PVCViewer created successfully.")
예제 #9
0
파일: get.py 프로젝트: arllanos/kubeflow
def get_pvcs(namespace):
    # Get the active viewers for each pvc as a dictionary
    # with Key:PVC name and Value:Status of Viewer
    viewers_lst = api.list_custom_rsrc(*utils.PVCVIEWER, namespace)

    viewers = {}
    for v in viewers_lst["items"]:
        pvc_name = v["spec"]["pvc"]
        viewers[pvc_name] = status.viewer_status(v)

    # Return the list of PVCs and the corresponding Viewer's state
    pvcs = api.list_pvcs(namespace)
    content = [utils.parse_pvc(pvc, viewers) for pvc in pvcs.items]

    return api.success_response("pvcs", content)
예제 #10
0
def get_poddefaults(namespace):
    pod_defaults = api.list_poddefaults(namespace)

    # Return a list of (label, desc) with the pod defaults
    contents = []
    for pd in pod_defaults["items"]:
        label = list(pd["spec"]["selector"]["matchLabels"].keys())[0]
        if "desc" in pd["spec"]:
            desc = pd["spec"]["desc"]
        else:
            desc = pd["metadata"]["name"]

        contents.append({"label": label, "desc": desc})

    log.info("Found poddefaults: %s", contents)
    return api.success_response("poddefaults", contents)
예제 #11
0
파일: delete.py 프로젝트: arllanos/kubeflow
def delete_pvc(pvc, namespace):
    """
    Delete a PVC only if it is not used from any Pod
    """
    pods = common_utils.get_pods_using_pvc(pvc, namespace)
    if pods:
        pod_names = [p.metadata.name for p in pods]
        raise exceptions.Conflict("Cannot delete PVC '%s' because it is being"
                                  " used by pods: %s" % (pvc, pod_names))

    log.info("Deleting PVC %s/%s...", namespace, pvc)
    api.delete_pvc(pvc, namespace)
    log.info("Successfully deleted PVC %s/%s", namespace, pvc)

    return api.success_response("message",
                                "PVC %s successfully deleted." % pvc)
예제 #12
0
파일: delete.py 프로젝트: arllanos/kubeflow
def delete_tensorboard(tensorboard, namespace):

    log.info("About to delete Tensorboard %s/%s", tensorboard, namespace)
    api.delete_custom_rsrc(
        "tensorboard.kubeflow.org",
        "v1alpha1",
        "tensorboards",
        tensorboard,
        namespace,
    )
    log.info(
        "DELETE request was sent to the API Server for Tensorboard: %s/%s",
        tensorboard,
        namespace,
    )

    return api.success_response("message", "Tensorboard deleted successfully.")
예제 #13
0
파일: patch.py 프로젝트: arllanos/kubeflow
def patch_notebook(namespace, notebook):
    request_body = request.get_json()
    log.info("Got body: %s", request_body)

    if request_body is None:
        raise exceptions.BadRequest("Request doesn't have a body.")

    # Ensure request has at least one valid command
    if not any(attr in ATTRIBUTES for attr in request_body.keys()):
        raise exceptions.BadRequest(
            "Request body must include at least one supported key: %s"
            % list(ATTRIBUTES)
        )

    # start/stop a notebook
    if STOP_ATTR in request_body:
        start_stop_notebook(namespace, notebook, request_body)

    return api.success_response()
예제 #14
0
파일: delete.py 프로젝트: arllanos/kubeflow
def delete_pvc(pvc, namespace):
    """
    Delete a PVC, even if it is only mounted on PVCViewer Pods.
    Get list of PVCViewers that use the requested PVC. If no other Pods
    are using that PVC then delete the Viewer Pods as well as the PVC.
    """
    pods = common_utils.get_pods_using_pvc(pvc, namespace)
    non_viewer_pods = [p for p in pods if not rok_utils.is_viewer_pod(p)]
    if non_viewer_pods:
        pod_names = [p.metadata.name for p in non_viewer_pods]
        raise exceptions.Conflict("Cannot delete PVC '%s' because it is being"
                                  " used by pods: %s" % (pvc, pod_names))

    log.info("Deleting PVC %s/%s...", namespace, pvc)
    api.delete_pvc(pvc, namespace)
    log.info("Successfully deleted PVC %s/%s", namespace, pvc)

    return api.success_response("message",
                                "PVC %s successfully deleted." % pvc)
예제 #15
0
def post_tensorboard(namespace):

    body = request.get_json()
    log.info("Got body: ", body)

    name = body["name"]

    tensorboard = utils.get_tensorboard_dict(namespace, body)

    log.info("About to create Tensorboard: %s", tensorboard)
    api.create_custom_rsrc(
        "tensorboard.kubeflow.org",
        "v1alpha1",
        "tensorboards",
        tensorboard,
        namespace,
    )
    log.info("Successfully created Tensorboard %s in namespace %s", name,
             namespace)

    return api.success_response("message", "Tensorboard created successfully.")
예제 #16
0
def get_gpu_vendors():
    """
    Return a list of GPU vendors for which at least one node has the necessary
    annotation required to schedule pods
    """
    frontend_config = utils.load_spawner_ui_config()
    gpus_value = frontend_config.get("gpus", {}).get("value", {})
    config_vendor_keys = [
        v.get("limitsKey", "") for v in gpus_value.get("vendors", [])
    ]

    # Get all of the different resources installed in all nodes
    installed_resources = set()
    nodes = api.list_nodes().items
    for node in nodes:
        installed_resources.update(node.status.capacity.keys())

    # Keep the vendors the key of which exists in at least one node
    available_vendors = installed_resources.intersection(config_vendor_keys)

    return api.success_response("vendors", list(available_vendors))
예제 #17
0
파일: post.py 프로젝트: arllanos/kubeflow
def post_notebook(namespace):
    body = request.get_json()
    log.info("Got body: %s" % body)

    notebook = helpers.load_param_yaml(
        utils.NOTEBOOK_TEMPLATE_YAML,
        name=body["name"],
        namespace=namespace,
        serviceAccount="default-editor",
    )

    defaults = utils.load_spawner_ui_config()

    form.set_notebook_image(notebook, body, defaults)
    form.set_notebook_image_pull_policy(notebook, body, defaults)
    form.set_server_type(notebook, body, defaults)
    form.set_notebook_cpu(notebook, body, defaults)
    form.set_notebook_memory(notebook, body, defaults)
    form.set_notebook_gpus(notebook, body, defaults)
    form.set_notebook_tolerations(notebook, body, defaults)
    form.set_notebook_affinity(notebook, body, defaults)
    form.set_notebook_configurations(notebook, body, defaults)
    form.set_notebook_environment(notebook, body, defaults)

    # Workspace Volume
    ws_pvc = None
    workspace_vol = form.get_workspace_vol(body, defaults)
    if not body.get("noWorkspace", False) and workspace_vol["type"] != "None":
        ws_pvc = rok_common.rok_pvc_from_dict(workspace_vol, namespace)

        rok_common.add_workspace_volume_annotations(ws_pvc, workspace_vol)

        form.add_notebook_volume(
            notebook,
            ws_pvc.metadata.name,
            ws_pvc.metadata.name,
            "/home/jovyan",
        )

    # Add the Data Volumes
    dtvol_pvcs = []
    for vol in form.get_data_vols(body, defaults):
        dtvol_pvc = rok_common.rok_pvc_from_dict(vol, namespace)
        dtvol_pvcs.append(dtvol_pvc)

        rok_common.add_data_volume_annotations(dtvol_pvc, vol)

        form.add_notebook_volume(
            notebook,
            dtvol_pvc.metadata.name,
            dtvol_pvc.metadata.name,
            vol["path"],
        )

    # shm
    form.set_notebook_shm(notebook, body, defaults)

    # Create the Notebook before creating the PVCs
    log.info("Creating Notebook: %s", notebook)
    notebook = api.create_notebook(notebook, namespace)

    # Create the PVCs with owner references to the Notebook
    if ws_pvc is not None:
        rok_common.add_owner_reference(ws_pvc, notebook)
        log.info("Creating Workspace Volume: %s", ws_pvc.to_dict())
        api.create_pvc(ws_pvc, namespace)

    for dtvol_pvc in dtvol_pvcs:
        rok_common.add_owner_reference(dtvol_pvc, notebook)
        log.info("Creating Data Volume %s:", dtvol_pvc)
        api.create_pvc(dtvol_pvc, namespace=namespace)

    return api.success_response("message", "Notebook created successfully.")
예제 #18
0
def post_pvc(namespace):
    body = request.get_json()
    log.info("Got body: %s" % body)

    notebook = helpers.load_param_yaml(
        utils.NOTEBOOK_TEMPLATE_YAML,
        name=body["name"],
        namespace=namespace,
        serviceAccount="default-editor",
    )

    defaults = utils.load_spawner_ui_config()

    form.set_notebook_image(notebook, body, defaults)
    form.set_notebook_image_pull_policy(notebook, body, defaults)
    form.set_server_type(notebook, body, defaults)
    form.set_notebook_cpu(notebook, body, defaults)
    form.set_notebook_memory(notebook, body, defaults)
    form.set_notebook_gpus(notebook, body, defaults)
    form.set_notebook_tolerations(notebook, body, defaults)
    form.set_notebook_affinity(notebook, body, defaults)
    form.set_notebook_configurations(notebook, body, defaults)
    form.set_notebook_shm(notebook, body, defaults)

    # Notebook volumes
    api_volumes = []
    api_volumes.extend(
        form.get_form_value(body, defaults, "datavols", "dataVolumes"))
    workspace = form.get_form_value(body,
                                    defaults,
                                    "workspace",
                                    "workspaceVolume",
                                    optional=True)
    if workspace:
        api_volumes.append(workspace)

    # ensure that all objects can be created
    api.create_notebook(notebook, namespace, dry_run=True)
    for api_volume in api_volumes:
        pvc = volumes.get_new_pvc(api_volume)
        if pvc is None:
            continue

        api.create_pvc(pvc, namespace, dry_run=True)

    # create the new PVCs and set the Notebook volumes and mounts
    for api_volume in api_volumes:
        pvc = volumes.get_new_pvc(api_volume)
        if pvc is not None:
            logging.info("Creating PVC: %s", pvc)
            pvc = api.create_pvc(pvc, namespace)

        v1_volume = volumes.get_pod_volume(api_volume, pvc)
        mount = volumes.get_container_mount(api_volume, v1_volume["name"])

        notebook = volumes.add_notebook_volume(notebook, v1_volume)
        notebook = volumes.add_notebook_container_mount(notebook, mount)

    log.info("Creating Notebook: %s", notebook)
    api.create_notebook(notebook, namespace)

    return api.success_response("message", "Notebook created successfully.")
예제 #19
0
def get_pvcs(namespace):
    # Return the list of PVCs and the corresponding Viewer's state
    pvcs = api.list_pvcs(namespace)
    content = [pvc.metadata.name for pvc in pvcs.items]

    return api.success_response("pvcs", content)
예제 #20
0
def get_inference_services(namespace):
    gvk = versions.inference_service_gvk()
    inference_services = api.list_custom_rsrc(**gvk, namespace=namespace)

    return api.success_response("inferenceServices",
                                inference_services["items"])
예제 #21
0
def get_knative_service(namespace, name):
    svc = api.get_custom_rsrc(**versions.KNATIVE_SERVICE, namespace=namespace,
                              name=name)

    return api.success_response("knativeService", svc)
예제 #22
0
def get_config():
    config = utils.load_spawner_ui_config()
    return api.success_response("config", config)
예제 #23
0
def get_notebooks(namespace):
    notebooks = api.list_notebooks(namespace)["items"]
    contents = [utils.notebook_dict_from_k8s_obj(nb) for nb in notebooks]

    return api.success_response("notebooks", contents)
예제 #24
0
def get_knative_revision(namespace, name):
    svc = api.get_custom_rsrc(**versions.KNATIVE_REVISION, namespace=namespace,
                              name=name)

    return api.success_response("knativeRevision", svc)
예제 #25
0
def get_knative_configuration(namespace, name):
    svc = api.get_custom_rsrc(**versions.KNATIVE_CONF, namespace=namespace,
                              name=name)

    return api.success_response("knativeConfiguration", svc)
예제 #26
0
파일: get.py 프로젝트: arllanos/kubeflow
def get_pvcs(namespace):
    pvcs = api.list_pvcs(namespace).items
    contents = [utils.pvc_dict_from_k8s_obj(pvc) for pvc in pvcs]

    return api.success_response("pvcs", contents)
예제 #27
0
def get_knative_route(namespace, name):
    svc = api.get_custom_rsrc(**versions.KNATIVE_ROUTE, namespace=namespace,
                              name=name)

    return api.success_response("knativeRoute", svc)
예제 #28
0
def get_pvcs(namespace):
    # Return the list of PVCs
    pvcs = api.list_pvcs(namespace)
    content = [utils.parse_pvc(pvc) for pvc in pvcs.items]

    return api.success_response("pvcs", content)
예제 #29
0
파일: get.py 프로젝트: inaba-minoru/my-kf
def get_pvcs(namespace):
    # Return the list of PVCs and the corresponding Viewer's state
    pvcs = api.list_pvcs(namespace)
    content = [utils.getPVCName(pvc) for pvc in pvcs.items]

    return api.success_response("pvcs", content)
예제 #30
0
def delete_notebook(notebook, namespace):
    log.info(f"Deleting Notebook '{namespace}/{notebook}'")
    api.delete_notebook(notebook, namespace)

    return api.success_response("message",
                                f"Notebook {notebook} successfully deleted.")