Example #1
0
 def conditions(self) -> section.PodConditions:
     # TODO: separate section for custom conditions
     return section.PodConditions(
         **{
             condition.type.value: section.PodCondition(
                 status=condition.status,
                 reason=condition.reason,
                 detail=condition.detail,
                 last_transition_time=condition.last_transition_time,
             )
             for condition in self.status.conditions
             if condition.type is not None
         })
Example #2
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]",
             ),
         ),
     )