Skip to content

Commit

Permalink
fix(k8s): check readiness probe for Dask service (#626)
Browse files Browse the repository at this point in the history
Closes #625
  • Loading branch information
Alputer committed Jan 23, 2025
1 parent 51fad95 commit c0b6c2a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
26 changes: 24 additions & 2 deletions reana_workflow_controller/k8s.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is part of REANA.
# Copyright (C) 2019, 2020, 2021, 2022, 2024 CERN.
# Copyright (C) 2019, 2020, 2021, 2022, 2024, 2025 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -487,10 +487,32 @@ def delete_dask_dashboard_ingress(cluster_name, workflow_id):
)


def check_pod_readiness_by_prefix(
pod_name_prefix, namespace=REANA_RUNTIME_KUBERNETES_NAMESPACE
):
"""Check the readiness of 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)

Check warning on line 495 in reana_workflow_controller/k8s.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/k8s.py#L494-L495

Added lines #L494 - L495 were not covered by tests

for pod in pods.items:
if pod.metadata.name.startswith(pod_name_prefix):

Check warning on line 498 in reana_workflow_controller/k8s.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/k8s.py#L497-L498

Added lines #L497 - L498 were not covered by tests
# Check the pod's readiness condition
if pod.status.conditions:
for condition in pod.status.conditions:
if condition.type == "Ready":
return (

Check warning on line 503 in reana_workflow_controller/k8s.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/k8s.py#L500-L503

Added lines #L500 - L503 were not covered by tests
"Ready" if condition.status == "True" else "Not Ready"
)
return "Not Ready"
return "Not Found"
except ApiException as e:
return f"Error: {e.reason}"

Check warning on line 509 in reana_workflow_controller/k8s.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/k8s.py#L506-L509

Added lines #L506 - L509 were not covered by tests


def check_pod_status_by_prefix(
pod_name_prefix, namespace=REANA_RUNTIME_KUBERNETES_NAMESPACE
):
"""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."""
"""Check the pod status of 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)

Expand Down
11 changes: 7 additions & 4 deletions reana_workflow_controller/rest/workflows.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2020, 2021, 2022, 2023 CERN.
# Copyright (C) 2020, 2021, 2022, 2023, 2025 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -59,7 +59,10 @@
use_paginate_args,
)

from reana_workflow_controller.k8s import check_pod_status_by_prefix
from reana_workflow_controller.k8s import (
check_pod_status_by_prefix,
check_pod_readiness_by_prefix,
)
from reana_workflow_controller.dask import requires_dask

START = "start"
Expand Down Expand Up @@ -412,11 +415,11 @@ def get_workflows(args, paginate=None): # noqa

dask_service = workflow.services.first()
if dask_service and dask_service.status == ServiceStatus.created:
pod_status = check_pod_status_by_prefix(
pod_readiness = check_pod_readiness_by_prefix(

Check warning on line 418 in reana_workflow_controller/rest/workflows.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/rest/workflows.py#L418

Added line #L418 was not covered by tests
pod_name_prefix=f"reana-run-dask-{workflow.id_}"
)

if pod_status == "Running":
if pod_readiness == "Ready":

Check warning on line 422 in reana_workflow_controller/rest/workflows.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/rest/workflows.py#L422

Added line #L422 was not covered by tests
dask_service.status = ServiceStatus.running
db_session = Session.object_session(dask_service)
db_session.commit()
Expand Down

0 comments on commit c0b6c2a

Please sign in to comment.