Skip to content

Commit

Permalink
Replace string reason check in k8s client with status check (#26644)
Browse files Browse the repository at this point in the history
Summary:
Both work, but string matching on a reason is more error-pone.

BK

> Insert changelog entry or delete this section.

## Summary & Motivation

## How I Tested These Changes

## Changelog

> Insert changelog entry or delete this section.
  • Loading branch information
gibsondan authored Dec 22, 2024
1 parent d8bac94 commit 3f5a73a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions python_modules/libraries/dagster-k8s/dagster_k8s/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def _get_job_status():
try:
job = self.batch_api.read_namespaced_job_status(job_name, namespace=namespace)
except kubernetes.client.rest.ApiException as e:
if e.reason == "Not Found":
if e.status == 404:
return None
else:
raise
Expand Down Expand Up @@ -518,14 +518,14 @@ def delete_job(
for error in errors:
if not (
isinstance(error, kubernetes.client.rest.ApiException)
and error.reason == "Not Found"
and error.status == 404
):
raise error
raise errors[0]

return True
except kubernetes.client.rest.ApiException as e:
if e.reason == "Not Found":
if e.status == 404:
return False
raise e

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ def test_check_run_health(kubeconfig_file):
assert health.status == WorkerStatus.FAILED, health.msg

mock_k8s_client_batch_api.read_namespaced_job_status.side_effect = (
kubernetes.client.rest.ApiException(reason="Not Found")
kubernetes.client.rest.ApiException(status=404, reason="Not Found")
)

finished_k8s_job_name = get_job_name_from_run_id(finished_run.run_id)
Expand Down

0 comments on commit 3f5a73a

Please sign in to comment.