Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

job-monitor: consider OOMKilled pods as failed #397

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Version 0.9.1 (UNRELEASED)

- Fixes intermittent Slurm connection issues by DNS-resolving the Slurm head node IPv4 address before establishing connections.
- Fixes deletion of failed jobs not being performed when Kerberos is enabled.
- Fixes job monitoring to consider OOM-killed jobs as failed.
- Changes Paramiko to version 3.0.0.
- Changes HTCondor to version 9.0.17 (LTS).

Expand Down
29 changes: 26 additions & 3 deletions reana_job_controller/job_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,37 @@
"""Get Kubernetes based REANA job status."""
status = None
backend_job_id = self.get_backend_job_id(job_pod)
container_statuses = self._get_job_container_statuses(job_pod)

if job_pod.status.phase == "Succeeded":
logging.info("Kubernetes job id: {} succeeded.".format(backend_job_id))
status = JobStatus.finished.name
# checking that all the containers are `Completed`, as sometimes there
# can be `OOMKilled` containers that are considered as successful
for container in container_statuses:
try:
reason = container.state.terminated.reason
except AttributeError:
reason = None

Check warning on line 183 in reana_job_controller/job_monitor.py

View check run for this annotation

Codecov / codecov/patch

reana_job_controller/job_monitor.py#L182-L183

Added lines #L182 - L183 were not covered by tests
if not reason:
logging.info(

Check warning on line 185 in reana_job_controller/job_monitor.py

View check run for this annotation

Codecov / codecov/patch

reana_job_controller/job_monitor.py#L185

Added line #L185 was not covered by tests
f"No termination reason for container {container.name} in "
f"Kubernetes job {backend_job_id}, assuming successful."
)
elif reason != "Completed":
logging.info(
f"Kubernetes job id: {backend_job_id} failed, phase 'Succeeded' but "
f"container '{container.name}' was terminated because of '{reason}'."
)
status = JobStatus.failed.name

if not status:
logging.info("Kubernetes job id: {} succeeded.".format(backend_job_id))
status = JobStatus.finished.name

elif job_pod.status.phase == "Failed":
logging.info("Kubernetes job id: {} failed.".format(backend_job_id))
status = JobStatus.failed.name

elif job_pod.status.phase == "Pending":
container_statuses = self._get_job_container_statuses(job_pod)
for container in container_statuses:
try:
reason = container.state.waiting.reason
Expand Down
4 changes: 4 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ start_db_container () {
docker run --rm --name postgres__reana-job-controller -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d docker.io/library/postgres:12.13
_check_ready "Postgres" _db_check
db_container_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' postgres__reana-job-controller)
if [[ -z $db_container_ip ]]; then
# container does not have an IP when using podman
db_container_ip="localhost"
fi
export REANA_SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://postgres:mysecretpassword@$db_container_ip/postgres
}

Expand Down
1 change: 1 addition & 0 deletions tests/test_job_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def test_kubernetes_get_job_logs(
("Succeeded", "Completed", "finished"),
("Failed", "Error", "failed"),
("Pending", ["Running", "ErrImagePull"], "failed"),
("Succeeded", "OOMKilled", "failed"),
],
)
def test_kubernetes_get_job_status(
Expand Down
Loading