Skip to content

Commit

Permalink
k8s: use unique error messages
Browse files Browse the repository at this point in the history
This commit changes the error messages used to log k8s API errors so
that each of them is unique. This will help to debug reanahub#383.
  • Loading branch information
mdonadoni committed Feb 27, 2023
1 parent 6aa13f2 commit 01c7ed9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 6 additions & 4 deletions reana_job_controller/job_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def clean_job(self, job_id):
self.job_manager_cls.stop(job_id)
self.job_db[self.get_reana_job_id(job_id)]["deleted"] = True
except client.rest.ApiException as e:
logging.error("Error while connecting to Kubernetes API: {}".format(e))
logging.error(f"Error from Kubernetes API while cleaning up job: {e}")
except Exception as e:
logging.error(traceback.format_exc())
logging.error("Unexpected error: {}".format(e))
Expand Down Expand Up @@ -236,7 +236,7 @@ def _get_containers_logs(self, job_pod) -> Optional[str]:

return pod_logs
except client.rest.ApiException as e:
logging.error("Error while connecting to Kubernetes API: {}".format(e))
logging.error(f"Error from Kubernetes API while getting job logs: {e}")
return None
except Exception as e:
logging.error(traceback.format_exc())
Expand Down Expand Up @@ -276,7 +276,7 @@ def watch_jobs(self, job_db, app=None):
:param job_db: Dictionary which contains all current jobs.
"""
while True:
logging.debug("Starting a new stream request to watch Jobs")
logging.info("Starting a new stream request to watch Jobs")
try:
w = watch.Watch()
for event in w.stream(
Expand All @@ -300,7 +300,9 @@ def watch_jobs(self, job_db, app=None):
if JobStatus.should_cleanup_job(job_status):
self.clean_job(backend_job_id)
except client.rest.ApiException as e:
logging.error("Error while connecting to Kubernetes API: {}".format(e))
logging.error(
f"Error from Kubernetes API while watching jobs pods: {e}"
)
except Exception as e:
logging.error(traceback.format_exc())
logging.error("Unexpected error: {}".format(e))
Expand Down
9 changes: 5 additions & 4 deletions reana_job_controller/kubernetes_job_manager.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 CERN.
# Copyright (C) 2019, 2020, 2021, 2022, 2023 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 @@ -250,7 +250,9 @@ def _submit(self):
)
return self.job["metadata"]["name"]
except ApiException as e:
logging.error("Error while connecting to Kubernetes" " API: {}".format(e))
logging.error(
f"An error has occurred while connecting to Kubernetes API to submit a job: {e}"
)
except Exception as e:
logging.error(traceback.format_exc())
logging.debug("Unexpected error: {}".format(e))
Expand All @@ -270,8 +272,7 @@ def stop(backend_job_id, asynchronous=True):
)
except ApiException as e:
logging.error(
"An error has occurred while connecting to Kubernetes API "
"Server \n {}".format(e)
f"An error has occurred while connecting to Kubernetes API to stop a job: {e}"
)
raise ComputingBackendSubmissionError(e.reason)

Expand Down

0 comments on commit 01c7ed9

Please sign in to comment.