Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zubenkoivan committed May 8, 2024
1 parent 461ebe3 commit 2919686
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions platform_monitoring/kube_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,10 @@ def from_primitive(cls, payload: JSON) -> t.Self:
def get_container_status(self, name: str) -> ContainerStatus:
for status in self.status.container_statuses:
if status.name == name:
return status.with_pod_restart_policy(self.spec.restart_policy)
return ContainerStatus(name=name)
break
else:
status = ContainerStatus(name=name)
return status.with_pod_restart_policy(self.spec.restart_policy)

def get_container_id(self, name: str) -> str | None:
for status in self.status.container_statuses:
Expand Down Expand Up @@ -383,7 +385,7 @@ class ContainerStatus:
state: t.Mapping[str, t.Any] = field(default_factory=dict)
last_state: t.Mapping[str, t.Any] = field(default_factory=dict)

pod_restart_policy: PodRestartPolicy = PodRestartPolicy.NEVER
pod_restart_policy: PodRestartPolicy = PodRestartPolicy.ALWAYS

@classmethod
def from_primitive(cls, payload: JSON) -> t.Self:
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/test_kube.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Pod,
PodContainerStats,
PodPhase,
PodRestartPolicy,
StatsSummary,
)
from platform_monitoring.logs import filter_out_rpc_error
Expand Down Expand Up @@ -63,7 +64,9 @@ def test_container_status(self) -> None:
}
)
container_status = pod.get_container_status("testcontainer")
assert container_status == ContainerStatus(name="testcontainer")
assert container_status == ContainerStatus(
name="testcontainer", pod_restart_policy=PodRestartPolicy.NEVER
)

def test_no_container_id(self) -> None:
pod = Pod.from_primitive(
Expand Down

0 comments on commit 2919686

Please sign in to comment.