Beispiel #1
0
def wait_for_pod_to_be_running(corev1: client.CoreV1Api, name: str,
                               namespace: str) -> None:
    print("Waiting for pod to be running")
    if not k8s_conditions.wait(
            lambda: corev1.read_namespaced_pod(name, namespace),
            lambda pod: pod.status.phase == "Running",
            sleep_time=5,
            timeout=90,
            exceptions_to_ignore=ApiException,
    ):
        raise Exception("Pod never got into Running state!")
Beispiel #2
0
def get_current_kfp_pod(client: k8s_client.CoreV1Api) -> k8s_client.V1Pod:
    """Get manifest of the KFP pod in which this program is running.

  Args:
    client: A kubernetes CoreV1Api client.
  Raises:
    RuntimeError: If KFP pod cannot be determined from the environment, i.e.
        this program is not running inside the KFP.
  Returns:
    The manifest of the pod this program is running on.
  """
    try:
        namespace = os.environ[KFP_NAMESPACE]
        pod_name = os.environ[KFP_POD_NAME]
        return client.read_namespaced_pod(name=pod_name, namespace=namespace)
    except KeyError:
        raise RuntimeError('Cannot determine KFP pod from the environment.')
Beispiel #3
0
    def test_pod_apis(self, k8s: client.CoreV1Api):
        name = 'test-' + str(uuid.uuid4())

        pod_manifest = {'apiVersion': 'v1',
                        'kind': 'Pod',
                        'metadata': {'color': 'blue', 'name': name},
                        'spec': {'containers': [{'image': 'alpine',
                                                 'name': 'test'}]}}

        resp = k8s.create_namespaced_pod(body=pod_manifest,
                                         namespace='default')
        assert name == resp.metadata.name
        assert resp.status.phase == 'Pending'

        resp = k8s.read_namespaced_pod(name=name,
                                       namespace='default')
        assert name == resp.metadata.name
        assert resp.status.phase == 'Pending'

        number_of_pods = len(k8s.list_pod_for_all_namespaces().items)
        assert number_of_pods > 0
Beispiel #4
0
def get_pod(core_api: k8s_client.CoreV1Api, pod_name: str,
            namespace: str) -> Optional[k8s_client.V1Pod]:
  """Get a pod from Kubernetes metadata API.

  Args:
    core_api: Client of Core V1 API of Kubernetes API.
    pod_name: The name of the Pod.
    namespace: The namespace of the Pod.

  Returns:
    The found Pod object. None if it's not found.
  Raises:
    RuntimeError: When it sees unexpected errors from Kubernetes API.
  """
  try:
    return core_api.read_namespaced_pod(name=pod_name, namespace=namespace)
  except k8s_client.rest.ApiException as e:
    if e.status != 404:
      raise RuntimeError('Unknown error! \nReason: %s\nBody: %s' %
                         (e.reason, e.body))
    return None
def _mock_current_kfp_pod(cli: client.CoreV1Api) -> client.V1Pod:
    """Mock method to get KFP pod manifest."""
    return cli.read_namespaced_pod(name=_KFP_PODNAME, namespace=_KFP_NAMESPACE)