Ejemplo n.º 1
0
def test_pod_status_evicted_pod() -> None:
    client_pod_status = client.V1PodStatus(
        conditions=None,
        container_statuses=None,
        ephemeral_container_statuses=None,
        host_ip=None,
        init_container_statuses=None,
        message="The node was low on resource: ephemeral-storage. Container "
        "grafana-sc-dashboard was using 4864Ki, which exceeds its request "
        "of 0. Container grafana was using 2112Ki, which exceeds its "
        "request of 0. Container grafana-sc-datasources was using 1280Ki, "
        "which exceeds its request of 0. ",
        nominated_node_name=None,
        phase="Failed",
        pod_i_ps=None,
        pod_ip=None,
        qos_class=None,
        reason="Evicted",
        start_time=datetime.datetime(2022, 5, 23, 5, 43, 57, tzinfo=tzutc()),
    )
    client_pod = client.V1Pod(status=client_pod_status)
    assert pod_status(client_pod) == api.PodStatus(
        conditions=None,
        phase=api.Phase.FAILED,
        start_time=api.Timestamp(1653284637.0),
        host_ip=None,
        pod_ip=None,
        qos_class=None,
    )
Ejemplo n.º 2
0
def default_pod(
    uid: str,
    metadata: Optional[api.PodMetaData] = None,
    attributes: Optional[Mapping[str, Any]] = None,
) -> Pod:
    if metadata is None:
        metadata = api.PodMetaData(name="", namespace="default")
    if attributes is None:
        attributes = {}
    return Pod(
        uid=api.PodUID(uid),
        metadata=metadata,
        status=api.PodStatus(
            conditions=[],
            phase=api.Phase.RUNNING,
            start_time=None,
            qos_class="burstable",
        ) if "status" not in attributes else attributes["status"],
        spec=api.PodSpec(
            restart_policy="Always", containers=[], init_containers=[])
        if "spec" not in attributes else attributes["spec"],
        containers={}
        if "containers" not in attributes else attributes["containers"],
        init_containers={} if "init_containers" not in attributes else
        attributes["init_containers"],
    )
Ejemplo n.º 3
0
    def test_pod_conditions_start_up_missing_fields(self) -> None:
        """
        In this specific instance all of the fields except for the scheduled field are missing.
        """
        pod = Pod(
            uid=Mock(),
            status=api.PodStatus(
                start_time=int(
                    convert_to_timestamp(
                        datetime.datetime(
                            2021, 11, 22, 16, 11, 38, 710257, tzinfo=datetime.timezone.utc
                        )
                    )
                ),
                conditions=[
                    api.PodCondition(
                        status=True,
                        type=api.ConditionType.PODSCHEDULED,
                        custom_type=None,
                        reason=None,
                        detail=None,
                    )
                ],
                phase=api.Phase.PENDING,
                qos_class="burstable",
            ),
            metadata=Mock(),
            spec=Mock(),
            containers=Mock(),
            init_containers=Mock(),
        )

        self.assertEqual(
            pod.conditions(),
            section.PodConditions(
                initialized=None,
                scheduled=section.PodCondition(status=True, reason=None, detail=None),
                containersready=None,
                ready=None,
            ),
        )
 def test_pod_conditions_start_up(self) -> None:
     """
     It is possible that during startup of pods, also more complete information arises.
     """
     pod_status = api.PodStatus(
         start_time=int(
             convert_to_timestamp(
                 datetime.datetime(2021, 11, 22, 16, 11, 38, 710257))),
         conditions=[
             api.PodCondition(
                 status=True,
                 type=api.ConditionType.INITIALIZED,
                 custom_type=None,
                 reason=None,
                 detail=None,
             ),
             api.PodCondition(
                 status=False,
                 type=api.ConditionType.READY,
                 custom_type=None,
                 reason="ContainersNotReady",
                 detail=
                 "containers with unready status: [unready_container]",
             ),
             api.PodCondition(
                 status=False,
                 type=api.ConditionType.CONTAINERSREADY,
                 custom_type=None,
                 reason="ContainersNotReady",
                 detail=
                 "containers with unready status: [unready_container]",
             ),
             api.PodCondition(
                 status=True,
                 type=api.ConditionType.PODSCHEDULED,
                 custom_type=None,
                 reason=None,
                 detail=None,
             ),
         ],
         phase=api.Phase.PENDING,
     )
     pod = Pod(
         uid=Mock(),
         status=pod_status,
         metadata=Mock(),
         spec=Mock(),
         resources=Mock(),
         containers=Mock(),
     )
     self.assertEqual(
         pod.conditions(),
         section.PodConditions(
             initialized=section.PodCondition(status=True,
                                              reason=None,
                                              detail=None),
             scheduled=section.PodCondition(status=True,
                                            reason=None,
                                            detail=None),
             containersready=section.PodCondition(
                 status=False,
                 reason="ContainersNotReady",
                 detail=
                 "containers with unready status: [unready_container]",
             ),
             ready=section.PodCondition(
                 status=False,
                 reason="ContainersNotReady",
                 detail=
                 "containers with unready status: [unready_container]",
             ),
         ),
     )