def print_failure_log_for_run(host: Text, run_id: Text, namespace: Text): """Prints logs of failed components of a run. Prints execution logs for failed componentsusing `logging.info`. This resembles the behavior of `argo logs` but uses K8s API directly. Don't print anything if the run was successful. Args: host: address of the KFP deployment. run_id: id of the execution of the pipeline. namespace: namespace of K8s cluster. """ client = kfp.Client(host=host) run = client.get_run(run_id=run_id) workflow_manifest = json.loads(run.pipeline_runtime.workflow_manifest) if kube_utils.PodPhase(workflow_manifest['status'] ['phase']) != kube_utils.PodPhase.FAILED: return k8s_client = kube_utils.make_core_v1_api() pods = [ i for i in workflow_manifest['status']['nodes'] if i['type'] == 'Pod' ] for pod in pods: if kube_utils.PodPhase(pod['phase']) != kube_utils.PodPhase.FAILED: continue display_name = pod['displayName'] pod_id = pod['id'] log = k8s_client.read_namespaced_pod_log(pod_id, namespace=namespace, container='main') for line in log.splitlines(): logging.info('%s:%s', display_name, line)
def _pod_is_done(resp: client.V1Pod): return kube_utils.PodPhase(resp.status.phase).is_done