Skip to content

Commit c242520

Browse files
authored
Merge branch 'main' into feat/k8s_pod_overlay
2 parents dc725d2 + 5957532 commit c242520

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

scripts/setup_pyre.sh

100644100755
File mode changed.

torchx/schedulers/kubernetes_scheduler.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -822,16 +822,23 @@ def _run_opts(self) -> runopts:
822822
return opts
823823

824824
def describe(self, app_id: str) -> Optional[DescribeAppResponse]:
825+
from kubernetes.client.rest import ApiException
826+
825827
namespace, name = app_id.split(":")
826828
roles = {}
827829
roles_statuses = {}
828-
resp = self._custom_objects_api().get_namespaced_custom_object_status(
829-
group="batch.volcano.sh",
830-
version="v1alpha1",
831-
namespace=namespace,
832-
plural="jobs",
833-
name=name,
834-
)
830+
try:
831+
resp = self._custom_objects_api().get_namespaced_custom_object_status(
832+
group="batch.volcano.sh",
833+
version="v1alpha1",
834+
namespace=namespace,
835+
plural="jobs",
836+
name=name,
837+
)
838+
except ApiException as e:
839+
if e.status == 404:
840+
return None
841+
raise
835842
status = resp.get("status")
836843
if status:
837844
state_str = status["state"]["phase"]

torchx/schedulers/test/kubernetes_scheduler_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,32 @@ def test_describe_unknown(
714714
),
715715
)
716716

717+
@patch("kubernetes.client.CustomObjectsApi.get_namespaced_custom_object_status")
718+
def test_describe_api_exception_404(
719+
self, get_namespaced_custom_object_status: MagicMock
720+
) -> None:
721+
from kubernetes.client.rest import ApiException
722+
723+
api_exc = ApiException(status=404, reason="Not Found")
724+
get_namespaced_custom_object_status.side_effect = api_exc
725+
app_id = "testnamespace:testid"
726+
scheduler = create_scheduler("test")
727+
info = scheduler.describe(app_id)
728+
self.assertIsNone(info)
729+
730+
@patch("kubernetes.client.CustomObjectsApi.get_namespaced_custom_object_status")
731+
def test_describe_api_exception_other(
732+
self, get_namespaced_custom_object_status: MagicMock
733+
) -> None:
734+
from kubernetes.client.rest import ApiException
735+
736+
api_exc = ApiException(status=500, reason="Internal Server Error")
737+
get_namespaced_custom_object_status.side_effect = api_exc
738+
app_id = "testnamespace:testid"
739+
scheduler = create_scheduler("test")
740+
with self.assertRaises(ApiException):
741+
scheduler.describe(app_id)
742+
717743
def test_runopts(self) -> None:
718744
scheduler = kubernetes_scheduler.create_scheduler("foo")
719745
runopts = scheduler.run_opts()

0 commit comments

Comments
 (0)