Skip to content

Commit

Permalink
[Runtimes] Don't explode listing runtime resources when CRD has no st…
Browse files Browse the repository at this point in the history
…atus (#912)
  • Loading branch information
Hedingber committed May 3, 2021
1 parent cd26eea commit 727a199
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mlrun/runtimes/base.py
Expand Up @@ -1603,7 +1603,7 @@ def _build_crd_resources(custom_objects) -> List:
{
"name": custom_object["metadata"]["name"],
"labels": custom_object["metadata"]["labels"],
"status": custom_object["status"],
"status": custom_object.get("status", {}),
}
)
return crd_resources
2 changes: 1 addition & 1 deletion tests/api/runtime_handlers/base.py
Expand Up @@ -235,7 +235,7 @@ def _assert_list_resources_response(
assert (
resources["crd_resources"][index]["labels"] == crd["metadata"]["labels"]
)
assert resources["crd_resources"][index]["status"] == crd["status"]
assert resources["crd_resources"][index]["status"] == crd.get("status", {})
assert len(resources["pod_resources"]) == len(expected_pods)
for index, pod in enumerate(expected_pods):
pod_dict = pod.to_dict()
Expand Down
15 changes: 12 additions & 3 deletions tests/api/runtime_handlers/test_mpijob.py
Expand Up @@ -27,6 +27,7 @@ def custom_setup(self):
self.failed_crd_dict = self._generate_mpijob_crd(
self.project, self.run_uid, self._get_failed_crd_status(),
)
self.no_status_crd_dict = self._generate_mpijob_crd(self.project, self.run_uid,)

launcher_pod_labels = {
"group-name": "kubeflow.org",
Expand Down Expand Up @@ -81,6 +82,15 @@ def test_list_resources(self):
expected_pods=pods,
)

def test_list_resources_with_crds_without_status(self):
mocked_responses = self._mock_list_namespaced_crds([[self.no_status_crd_dict]])
pods = self._mock_list_resources_pods()
self._assert_runtime_handler_list_resources(
RuntimeKinds.mpijob,
expected_crds=mocked_responses[0]["items"],
expected_pods=pods,
)

def test_list_resources_grouped_by_job(self, db: Session, client: TestClient):
mocked_responses = self._mock_list_namespaced_crds([[self.succeeded_crd_dict]])
pods = self._mock_list_resources_pods()
Expand Down Expand Up @@ -266,8 +276,6 @@ def _mock_list_resources_pods(self):

@staticmethod
def _generate_mpijob_crd(project, uid, status=None):
if status is None:
status = TestMPIjobRuntimeHandler._get_succeeded_crd_status()
crd_dict = {
"metadata": {
"name": "train-eaf63df8",
Expand All @@ -282,8 +290,9 @@ def _generate_mpijob_crd(project, uid, status=None):
"mlrun/uid": uid,
},
},
"status": status,
}
if status is not None:
crd_dict["status"] = status
return crd_dict

@staticmethod
Expand Down

0 comments on commit 727a199

Please sign in to comment.