Skip to content

Commit 0ada93d

Browse files
authored
Merge branch 'main' into feat/k8s_validate_pod_spec
2 parents c1a6a40 + 5957532 commit 0ada93d

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
@@ -743,16 +743,23 @@ def _run_opts(self) -> runopts:
743743
return opts
744744

745745
def describe(self, app_id: str) -> Optional[DescribeAppResponse]:
746+
from kubernetes.client.rest import ApiException
747+
746748
namespace, name = app_id.split(":")
747749
roles = {}
748750
roles_statuses = {}
749-
resp = self._custom_objects_api().get_namespaced_custom_object_status(
750-
group="batch.volcano.sh",
751-
version="v1alpha1",
752-
namespace=namespace,
753-
plural="jobs",
754-
name=name,
755-
)
751+
try:
752+
resp = self._custom_objects_api().get_namespaced_custom_object_status(
753+
group="batch.volcano.sh",
754+
version="v1alpha1",
755+
namespace=namespace,
756+
plural="jobs",
757+
name=name,
758+
)
759+
except ApiException as e:
760+
if e.status == 404:
761+
return None
762+
raise
756763
status = resp.get("status")
757764
if status:
758765
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
@@ -760,6 +760,32 @@ def test_describe_unknown(
760760
),
761761
)
762762

763+
@patch("kubernetes.client.CustomObjectsApi.get_namespaced_custom_object_status")
764+
def test_describe_api_exception_404(
765+
self, get_namespaced_custom_object_status: MagicMock
766+
) -> None:
767+
from kubernetes.client.rest import ApiException
768+
769+
api_exc = ApiException(status=404, reason="Not Found")
770+
get_namespaced_custom_object_status.side_effect = api_exc
771+
app_id = "testnamespace:testid"
772+
scheduler = create_scheduler("test")
773+
info = scheduler.describe(app_id)
774+
self.assertIsNone(info)
775+
776+
@patch("kubernetes.client.CustomObjectsApi.get_namespaced_custom_object_status")
777+
def test_describe_api_exception_other(
778+
self, get_namespaced_custom_object_status: MagicMock
779+
) -> None:
780+
from kubernetes.client.rest import ApiException
781+
782+
api_exc = ApiException(status=500, reason="Internal Server Error")
783+
get_namespaced_custom_object_status.side_effect = api_exc
784+
app_id = "testnamespace:testid"
785+
scheduler = create_scheduler("test")
786+
with self.assertRaises(ApiException):
787+
scheduler.describe(app_id)
788+
763789
def test_runopts(self) -> None:
764790
scheduler = kubernetes_scheduler.create_scheduler("foo")
765791
runopts = scheduler.run_opts()

0 commit comments

Comments
 (0)