Skip to content

Commit

Permalink
Check for container statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
akislou committed May 5, 2023
1 parent ba5be83 commit c463a20
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions kubeluigi/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def pod_spec_from_dict(
spec = dict(spec_schema)

for container in spec_schema["containers"]:

if "imagePullPolicy" in container:
container["image_pull_policy"] = container.pop("imagePullPolicy")

Expand Down Expand Up @@ -168,17 +167,23 @@ def reduce_job_state(pods: List[V1Pod]):
job_state = "Mixed"

for pod in pods:

pod_state = pod.status.phase

# Boil down all container states into one pod state.
for status in pod.status.container_statuses:
if status.state.waiting and status.state.waiting.reason == "InvalidImageName":
pod_state = "Failed"
error_message = "Invalid Image"

if status.state.terminated and status.state.terminated.reason == 'Error':
pod_state = "Failed"
if pod.status.container_statuses is not None:
for status in pod.status.container_statuses:
if (
status.state.waiting
and status.state.waiting.reason == "InvalidImageName"
):
pod_state = "Failed"
error_message = "Invalid Image"

if (
status.state.terminated
and status.state.terminated.reason == "Error"
):
pod_state = "Failed"

pod_states.append(pod_state)

Expand All @@ -199,7 +204,6 @@ def job_phase_stream(job):
previous_job_state = None

while True:

sleep(DEFAULT_POLL_INTERVAL)
pods = get_job_pods(job)
job_state, error_message = reduce_job_state(pods)
Expand Down

0 comments on commit c463a20

Please sign in to comment.