Skip to content

Commit

Permalink
fix(sessions): get the session status from the pod state (reanahub#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alputer committed Nov 18, 2024
1 parent 7896c61 commit a50932b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
17 changes: 17 additions & 0 deletions reana_workflow_controller/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,20 @@ def delete_dask_dashboard_ingress(cluster_name, workflow_id):
plural="middlewares",
name=f"replacepath-{workflow_id}",
)


def check_pod_by_prefix(pod_name_prefix, namespace="default"):
"""Check if there is a Pod in the given namespace whose name starts with the specified prefix. We assume that there exists 0 or 1 pod with a given prefix."""
try:
pods = current_k8s_corev1_api_client.list_namespaced_pod(namespace=namespace)

for pod in pods.items:
if pod.metadata.name.startswith(pod_name_prefix):
if pod.status.phase == "Running":
return "Running"
else:
return "Not Ready"

return "Not Found"
except ApiException as e:
return f"Error: {e.reason}"
11 changes: 10 additions & 1 deletion reana_workflow_controller/rest/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from webargs import fields, validate
from webargs.flaskparser import use_args, use_kwargs
from reana_commons.config import WORKFLOW_TIME_FORMAT
from reana_commons.utils import build_unique_component_name
from reana_db.database import Session
from reana_db.models import RunStatus, User, UserWorkflow, Workflow, WorkflowResource
from reana_db.utils import (
Expand All @@ -48,6 +49,8 @@
use_paginate_args,
)

from reana_workflow_controller.k8s import check_pod_by_prefix

START = "start"
STOP = "stop"
DELETED = "deleted"
Expand Down Expand Up @@ -398,7 +401,13 @@ def get_workflows(args, paginate=None): # noqa
if int_session:
workflow_response["session_type"] = int_session.type_.name
workflow_response["session_uri"] = int_session.path
workflow_response["session_status"] = int_session.status.name
int_session_pod_name_prefix = build_unique_component_name(
"run-session", int_session.workflow[0].id_
)
workflow_response["session_status"] = check_pod_by_prefix(
pod_name_prefix=int_session_pod_name_prefix
)

# Skip workflow if type is interactive and there is no session
elif type_ == "interactive":
continue
Expand Down

0 comments on commit a50932b

Please sign in to comment.