Skip to content

Commit

Permalink
fix(k8s): handle 409 conflict errors for dask resources (#618)
Browse files Browse the repository at this point in the history
Closes #617
  • Loading branch information
Alputer committed Nov 28, 2024
1 parent 7896c61 commit b9bd76d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
12 changes: 12 additions & 0 deletions reana_workflow_controller/dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from flask import current_app

from kubernetes.client.exceptions import ApiException

from reana_commons.config import (
K8S_CERN_EOS_AVAILABLE,
K8S_CERN_EOS_MOUNT_CONFIGURATION,
Expand Down Expand Up @@ -489,6 +491,11 @@ def _create_dask_cluster(self):
namespace="default",
body=self.cluster_body,
)
except ApiException as e:
if e.status == 409:
logging.error("Conflict error: Dask cluster already exists.")

Check warning on line 496 in reana_workflow_controller/dask.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/dask.py#L494-L496

Added lines #L494 - L496 were not covered by tests
else:
raise

Check warning on line 498 in reana_workflow_controller/dask.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/dask.py#L498

Added line #L498 was not covered by tests
except Exception:
logging.exception(
"An error occurred while trying to create a Dask cluster."
Expand All @@ -505,6 +512,11 @@ def _create_dask_autoscaler(self):
namespace="default",
body=self.autoscaler_body,
)
except ApiException as e:
if e.status == 409:
logging.error("Conflict error: Dask autoscaler already exists.")

Check warning on line 517 in reana_workflow_controller/dask.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/dask.py#L515-L517

Added lines #L515 - L517 were not covered by tests
else:
raise

Check warning on line 519 in reana_workflow_controller/dask.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/dask.py#L519

Added line #L519 was not covered by tests
except Exception:
logging.exception(
"An error occurred while trying to create a Dask autoscaler."
Expand Down
46 changes: 31 additions & 15 deletions reana_workflow_controller/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

"""REANA Workflow Controller Kubernetes utils."""

import logging

from kubernetes import client
from kubernetes.client.rest import ApiException
from reana_commons.config import (
Expand Down Expand Up @@ -451,14 +453,22 @@ def create_dask_dashboard_ingress(cluster_name, workflow_id):
if REANA_INGRESS_CLASS_NAME:
ingress.spec.ingress_class_name = REANA_INGRESS_CLASS_NAME

# Create middleware for ingress
current_k8s_custom_objects_api_client.create_namespaced_custom_object(
group="traefik.io",
version="v1alpha1",
namespace="default",
plural="middlewares",
body=middleware_spec,
)
try:

Check warning on line 456 in reana_workflow_controller/k8s.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/k8s.py#L456

Added line #L456 was not covered by tests
# Create middleware for ingress
current_k8s_custom_objects_api_client.create_namespaced_custom_object(

Check warning on line 458 in reana_workflow_controller/k8s.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/k8s.py#L458

Added line #L458 was not covered by tests
group="traefik.io",
version="v1alpha1",
namespace="default",
plural="middlewares",
body=middleware_spec,
)
except ApiException as e:
if e.status == 409:
logging.error(

Check warning on line 467 in reana_workflow_controller/k8s.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/k8s.py#L465-L467

Added lines #L465 - L467 were not covered by tests
"Conflict error: Dask dashboard ingress middleware already exists."
)
else:
raise

Check warning on line 471 in reana_workflow_controller/k8s.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/k8s.py#L471

Added line #L471 was not covered by tests
# Create the ingress resource
current_k8s_networking_api_client.create_namespaced_ingress(
namespace="default", body=ingress
Expand All @@ -470,10 +480,16 @@ def delete_dask_dashboard_ingress(cluster_name, workflow_id):
current_k8s_networking_api_client.delete_namespaced_ingress(
name=cluster_name, namespace="default", body=client.V1DeleteOptions()
)
current_k8s_custom_objects_api_client.delete_namespaced_custom_object(
group="traefik.io",
version="v1alpha1",
namespace="default",
plural="middlewares",
name=f"replacepath-{workflow_id}",
)
try:
current_k8s_custom_objects_api_client.delete_namespaced_custom_object(

Check warning on line 484 in reana_workflow_controller/k8s.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/k8s.py#L483-L484

Added lines #L483 - L484 were not covered by tests
group="traefik.io",
version="v1alpha1",
namespace="default",
plural="middlewares",
name=f"replacepath-{workflow_id}",
)
except ApiException as e:
if e.status == 409:
logging.error("Conflict error: Dask dashboard ingress already exists.")

Check warning on line 493 in reana_workflow_controller/k8s.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/k8s.py#L491-L493

Added lines #L491 - L493 were not covered by tests
else:
raise

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#L495

Added line #L495 was not covered by tests

0 comments on commit b9bd76d

Please sign in to comment.