Beispiel #1
0
def get_trial(name, namespace, api_version=KATIB_API_VERSION_V1BETA1):
    """Get a Trial."""
    k8s_client = k8sutils.get_co_client()
    return k8s_client.get_namespaced_custom_object(KATIB_API_GROUP,
                                                   api_version,
                                                   namespace,
                                                   KATIB_TRIALS_PLURAL, name)
Beispiel #2
0
def list_experiments(namespace, api_version=KATIB_API_VERSION_V1BETA1):
    """List Katib Experiments."""
    k8s_co_client = k8sutils.get_co_client()
    log.info("Listing Katib %s Experiment n namespace '%s'...",
             api_version, namespace)
    ret = k8s_co_client.list_namespaced_custom_object(
        KATIB_API_GROUP, api_version, namespace, KATIB_EXPERIMENTS_PLURAL)
    log.info("Successfully retrieved %d %s Experiments", len(ret), api_version)
    return ret
Beispiel #3
0
 def delete(self):
     """Delete the InferenceService CR."""
     namespace = podutils.get_namespace()
     log.info("Deleting InferenceServer '%s/%s'...", namespace, self.name)
     k8s_co_client = k8sutils.get_co_client()
     k8s_co_client.delete_namespaced_custom_object(CO_GROUP, CO_VERSION,
                                                   namespace, CO_PLURAL,
                                                   self.name)
     log.info("Successfully deleted InferenceService.")
Beispiel #4
0
def create_experiment(experiment, namespace):
    """Create a Katib Experiment."""
    k8s_co_client = k8sutils.get_co_client()
    log.info("Creating Katib Experiment '%s/%s'...",
             namespace, experiment["metadata"]["name"])
    api_version = experiment["apiVersion"].split("/")[1]
    exp = k8s_co_client.create_namespaced_custom_object(
        KATIB_API_GROUP, api_version, namespace,
        KATIB_EXPERIMENTS_PLURAL, experiment)
    log.info("Successfully created Katib Experiment!")
    return exp
Beispiel #5
0
def _submit_inference_service(inference_service: Dict, namespace: str):
    k8s_co_client = k8sutils.get_co_client()

    name = inference_service["metadata"]["name"]
    log.info("Creating InferenceService '%s'...", name)
    try:
        k8s_co_client.create_namespaced_custom_object(CO_GROUP, CO_VERSION,
                                                      namespace, CO_PLURAL,
                                                      inference_service)
    except ApiException:
        log.exception("Failed to create InferenceService")
        raise
    log.info("Successfully created InferenceService: %s", name)
Beispiel #6
0
def list_poddefaults(namespace: str = None):
    """List PodDefaults in requested namespace.

    If namespace is not provided, list PodDefaults in pod's namespace.
    """
    if not namespace:
        try:
            namespace = podutils.get_namespace()
        except Exception:
            raise ValueError("'namespace' cannot be empty when not inside a"
                             " pod")
    api_group = "kubeflow.org"
    api_version = "v1alpha1"
    co_name = "poddefaults"
    co_client = k8sutils.get_co_client()
    return co_client.list_namespaced_custom_object(api_group, api_version,
                                                   namespace, co_name)["items"]
Beispiel #7
0
def get_experiment(request, experiment, namespace):
    """Get a Katib Experiment.

    This RPC is used by the labextension when polling for the state of a
    running Experiment.

    Args:
        request: RPC request object
        experiment: Name of the Katib experiment
        namespace: Namespace of the experiment

    Returns (dict): a dict describing the status of the running experiment
    """
    k8s_co_client = k8sutils.get_co_client()

    co_group = "kubeflow.org"
    co_version = "v1alpha3"
    co_plural = "experiments"

    try:
        exp = k8s_co_client.get_namespaced_custom_object(
            co_group, co_version, namespace, co_plural, experiment)
    except ApiException as e:
        request.log.exception("Failed to get Katib experiment")
        raise RPCUnhandledError(message="Failed to get Katib experiment",
                                details=str(e),
                                trans_id=request.trans_id)

    ret = _construct_experiment_return_base(exp, namespace)
    if exp.get("status") is None:
        return ret

    status, reason, message = _get_experiment_status(exp["status"])
    ret.update({
        "status": status,
        "reason": reason,
        "message": message,
        "trials": exp["status"].get("trials", 0),
        "trialsFailed": exp["status"].get("trialsFailed", 0),
        "trialsRunning": exp["status"].get("trialsRunning", 0),
        "trialsSucceeded": exp["status"].get("trialsSucceeded", 0),
        "currentOptimalTrial": exp["status"].get("currentOptimalTrial")
    })
    return ret
Beispiel #8
0
def _launch_katib_experiment(request, katib_experiment, namespace):
    """Launch Katib experiment."""
    k8s_co_client = k8sutils.get_co_client()

    co_group = "kubeflow.org"
    co_version = "v1alpha3"
    co_plural = "experiments"

    request.log.debug("Launching Katib Experiment '%s'...",
                      katib_experiment["metadata"]["name"])
    try:
        k8s_co_client.create_namespaced_custom_object(co_group, co_version,
                                                      namespace, co_plural,
                                                      katib_experiment)
    except ApiException as e:
        request.log.exception("Failed to launch Katib experiment")
        raise RPCUnhandledError(message="Failed to launch Katib experiment",
                                details=str(e), trans_id=request.trans_id)
    request.log.info("Successfully launched Katib Experiment")
Beispiel #9
0
def get_run_uuid():
    """Get the Workflow's UUID form inside a pipeline step."""
    # Retrieve the pod
    pod_name = get_pod_name()
    namespace = get_namespace()
    workflow_name = workflowutils.get_workflow_name(pod_name, namespace)

    # Retrieve the Argo workflow
    api_group = "argoproj.io"
    api_version = "v1alpha1"
    co_name = "workflows"
    co_client = k8sutils.get_co_client()
    workflow = co_client.get_namespaced_custom_object(api_group, api_version,
                                                      namespace, co_name,
                                                      workflow_name)
    run_uuid = workflow["metadata"].get("labels", {}).get(KFP_RUN_ID_LABEL_KEY,
                                                          None)

    # KFP api-server adds run UUID as label to workflows for KFP>=0.1.26.
    # Return run UUID if available. Else return workflow UUID to maintain
    # backwards compatibility.
    return run_uuid or workflow["metadata"]["uid"]
Beispiel #10
0
def get_workflow(name, namespace):
    """Get a workflow."""
    co_client = k8sutils.get_co_client()
    return co_client.get_namespaced_custom_object(ARGO_API_GROUP,
                                                  ARGO_API_VERSION, namespace,
                                                  ARGO_WORKFLOWS_PLURAL, name)
Beispiel #11
0
def get_inference_service(name: str):
    """Get an InferenceService object."""
    k8s_co_client = k8sutils.get_co_client()
    ns = podutils.get_namespace()
    return k8s_co_client.get_namespaced_custom_object(CO_GROUP, CO_VERSION, ns,
                                                      CO_PLURAL, name)