def test_pod_conditions_pod_without_node(self) -> None:
     last_transition_time = datetime.datetime(2021,
                                              10,
                                              29,
                                              9,
                                              5,
                                              52,
                                              tzinfo=tzutc())
     pod_condition_list = [
         client.V1PodCondition(
             last_probe_time=None,
             last_transition_time=last_transition_time,
             message="0/1 nodes are available: 1 Too many pods.",
             reason="Unschedulable",
             status="False",
             type="PodScheduled",
         )
     ]
     self.assertEqual(
         pod_conditions(pod_condition_list),
         [
             api.PodCondition(
                 status=False,
                 type=api.ConditionType.PODSCHEDULED,
                 custom_type=None,
                 reason="Unschedulable",
                 detail="0/1 nodes are available: 1 Too many pods.",
                 last_transition_time=convert_to_timestamp(
                     last_transition_time))
         ],
     )
Ejemplo n.º 2
0
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