Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle case where container_statuses is None #1973

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions backend/capellacollab/sessions/operators/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,29 +228,30 @@ def _get_container_state(
self,
status: client.V1PodStatus,
) -> sessions_models.SessionState:
container_statuses = [
container_status
for container_status in status.container_statuses
if container_status.name == "session"
]
if not container_statuses:
return sessions_models.SessionState.UNKNOWN
if status.container_statuses:
container_statuses = [
container_status
for container_status in status.container_statuses
if container_status.name == "session"
]
if not container_statuses:
return sessions_models.SessionState.UNKNOWN

state: client.V1ContainerState = container_statuses[0].state
state: client.V1ContainerState = container_statuses[0].state

if state.running:
return sessions_models.SessionState.RUNNING
if state.waiting:
waiting: client.V1ContainerStateWaiting = state.waiting
if state.running:
return sessions_models.SessionState.RUNNING
if state.waiting:
waiting: client.V1ContainerStateWaiting = state.waiting

# https://github.com/kubernetes/kubernetes/blob/da215bf06a3b8ac3da4e0adb110dc5acc7f61fe1/pkg/kubelet/kubelet_pods.go#L83
if waiting.reason in ("ContainerCreating", "PodInitializing"):
return sessions_models.SessionState.PENDING
# https://github.com/kubernetes/kubernetes/blob/da215bf06a3b8ac3da4e0adb110dc5acc7f61fe1/pkg/kubelet/kubelet_pods.go#L83
if waiting.reason in ("ContainerCreating", "PodInitializing"):
return sessions_models.SessionState.PENDING

# Handle errors like ImagePullBackOff properly
return sessions_models.SessionState.FAILED
if state.terminated:
return sessions_models.SessionState.TERMINATED
# Handle errors like ImagePullBackOff properly
return sessions_models.SessionState.FAILED
if state.terminated:
return sessions_models.SessionState.TERMINATED

return sessions_models.SessionState.UNKNOWN

Expand Down
Loading