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"], )
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]", ), ), )