diff --git a/mlrun/runtimes/base.py b/mlrun/runtimes/base.py index e8b1e3a127f..32d390399d5 100644 --- a/mlrun/runtimes/base.py +++ b/mlrun/runtimes/base.py @@ -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 diff --git a/tests/api/runtime_handlers/base.py b/tests/api/runtime_handlers/base.py index a9e63d0a60a..27d2cdc38bf 100644 --- a/tests/api/runtime_handlers/base.py +++ b/tests/api/runtime_handlers/base.py @@ -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() diff --git a/tests/api/runtime_handlers/test_mpijob.py b/tests/api/runtime_handlers/test_mpijob.py index fd4d4617c16..4121fa2e2f3 100644 --- a/tests/api/runtime_handlers/test_mpijob.py +++ b/tests/api/runtime_handlers/test_mpijob.py @@ -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", @@ -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() @@ -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", @@ -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