Skip to content

Commit

Permalink
add specific exceptions for not permitted/not found for argo-workflow…
Browse files Browse the repository at this point in the history
…s delete (Netflix#2094)
  • Loading branch information
saikonen authored Oct 14, 2024
1 parent 561c5a9 commit aae3972
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions metaflow/plugins/argo/argo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ class ArgoClientException(MetaflowException):
headline = "Argo Client error"


class ArgoResourceNotFound(MetaflowException):
headline = "Resource not found"


class ArgoNotPermitted(MetaflowException):
headline = "Operation not permitted"


class ArgoClient(object):
def __init__(self, namespace=None):
self._client = KubernetesClient()
Expand Down Expand Up @@ -140,9 +148,7 @@ def delete_cronworkflow(self, name):
if e.status == 404:
return None
else:
raise ArgoClientException(
json.loads(e.body)["message"] if e.body is not None else e.reason
)
raise wrap_api_error(e)

def delete_workflow_template(self, name):
"""
Expand All @@ -164,9 +170,7 @@ def delete_workflow_template(self, name):
if e.status == 404:
return None
else:
raise ArgoClientException(
json.loads(e.body)["message"] if e.body is not None else e.reason
)
raise wrap_api_error(e)

def terminate_workflow(self, name):
client = self._client.get()
Expand Down Expand Up @@ -428,6 +432,18 @@ def delete_sensor(self, name):
except client.rest.ApiException as e:
if e.status == 404:
return None
raise ArgoClientException(
json.loads(e.body)["message"] if e.body is not None else e.reason
)
raise wrap_api_error(e)


def wrap_api_error(error):
message = (
json.loads(error.body)["message"] if error.body is not None else error.reason
)
# catch all
ex = ArgoClientException(message)
if error.status == 404:
# usually handled outside this function as most cases want to return None instead.
ex = ArgoResourceNotFound(message)
if error.status == 403:
ex = ArgoNotPermitted(message)
return ex

0 comments on commit aae3972

Please sign in to comment.