def create_pod_object(name: str = "default",
                      imagename: str = None,
                      labels: {} = None,
                      state: str = "running",
                      namespace: str = "default",
                      node_name='node1') -> k8sClient.V1Pod:
    container_state = k8sClient.V1ContainerState(running=MagicMock())
    if state == "terminated":
        container_state = k8sClient.V1ContainerState(terminated=MagicMock())

    image = k8sClient.V1ContainerImage(names=[imagename])
    container_status = k8sClient.V1ContainerStatus(state=container_state,
                                                   image=image,
                                                   image_id="fakeimage",
                                                   name="fakename",
                                                   ready="True",
                                                   restart_count=0)

    condition = k8sClient.V1PodCondition(type="Ready",
                                         status=[container_status])
    status = k8sClient.V1PodStatus(conditions=[condition],
                                   container_statuses=[container_status])
    container = k8sClient.V1Container(image=image, name="fakename1")
    spec = k8sClient.V1PodSpec(containers=[container], node_name=node_name)

    metadata = k8sClient.V1ObjectMeta(name=name,
                                      labels=labels,
                                      namespace=namespace)
    node = k8sClient.V1Pod(status=status, spec=spec, metadata=metadata)
    return node
Exemple #2
0
 def _generate_pod(name, labels, phase=PodPhases.succeeded):
     terminated_container_state = client.V1ContainerStateTerminated(
         finished_at=datetime.now(timezone.utc), exit_code=0
     )
     container_state = client.V1ContainerState(terminated=terminated_container_state)
     container_status = client.V1ContainerStatus(
         state=container_state,
         image="must/provide:image",
         image_id="must-provide-image-id",
         name="must-provide-name",
         ready=True,
         restart_count=0,
     )
     status = client.V1PodStatus(phase=phase, container_statuses=[container_status])
     metadata = client.V1ObjectMeta(
         name=name, labels=labels, namespace=get_k8s().resolve_namespace()
     )
     pod = client.V1Pod(metadata=metadata, status=status)
     return pod
Exemple #3
0
 def _generate_pod(namespace, pod):
     terminated_container_state = client.V1ContainerStateTerminated(
         finished_at=datetime.now(timezone.utc), exit_code=0)
     container_state = client.V1ContainerState(
         terminated=terminated_container_state)
     container_status = client.V1ContainerStatus(
         state=container_state,
         image=self.image_name,
         image_id="must-provide-image-id",
         name=self.name,
         ready=True,
         restart_count=0,
     )
     status = client.V1PodStatus(phase=PodPhases.succeeded,
                                 container_statuses=[container_status])
     response_pod = deepcopy(pod)
     response_pod.status = status
     response_pod.metadata.name = "test-pod"
     response_pod.metadata.namespace = namespace
     return response_pod
 def test_pod_containers_start_up(self) -> None:
     """
     In this specific instance all of the fields expect for the scheduled field are missing.
     """
     container_statuses = [
         client.V1ContainerStatus(
             name="unready_container",
             ready=False,
             restart_count=0,
             container_id=None,
             image="gcr.io/kuar-demo/kuard-amd64:blue",
             image_id="",
             state=client.V1ContainerState(
                 running=None,
                 terminated=None,
                 waiting=client.V1ContainerStateWaiting(
                     message=None, reason="ContainerCreating"),
             ),
         )
     ]
     self.assertEqual(
         pod_containers(container_statuses),
         {
             "unready_container":
             api.ContainerStatus(
                 id=None,
                 name="unready_container",
                 image="gcr.io/kuar-demo/kuard-amd64:blue",
                 image_id="",
                 ready=False,
                 state=api.ContainerWaitingState(type="waiting",
                                                 reason="ContainerCreating",
                                                 detail=None),
                 restart_count=0,
             )
         },
     )
Exemple #5
0
 def test_list1IpedWorker(self):
     state = client.V1ContainerState(running=None)
     containerStatus = client.V1ContainerStatus(image='image',
                                                image_id='1',
                                                name='2',
                                                ready=True,
                                                restart_count=0,
                                                state=state)
     status = client.V1PodStatus(host_ip="1.2.3.4",
                                 pod_ip='6.7.8.9',
                                 container_statuses=[containerStatus])
     metadata = client.V1ObjectMeta(name='ipedworker-myname')
     spec = client.V1PodSpec(node_name='sardcloudXX', containers=[])
     pods = [client.V1Pod(status=status, metadata=metadata, spec=spec)]
     podList = client.V1PodList(items=pods)
     workers: List[IPEDWorker] = _listWorkers(podList)
     self.assertEqual(len(workers), 1)
     w0: IPEDWorker = workers[0]
     self.assertEqual(w0.name, "ipedworker-myname")
     self.assertEqual(w0.host_ip, "1.2.3.4")
     self.assertEqual(w0.pod_ip, "6.7.8.9")
     self.assertEqual(w0.node_name, "sardcloudXX")
     self.assertEqual(w0.ready, True)
     self.assertEqual(w0.image, 'image')