Skip to content

Commit 1f606fb

Browse files
committed
Adding constant, adding error checking, adding documentation
1 parent 93b0608 commit 1f606fb

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

docs/sphinx/user-docs/ray-cluster-interaction.rst

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ cluster.up()
6666

6767
| The ``cluster.up()`` function creates a Ray Cluster in the given namespace.
6868
69+
cluster.apply()
70+
------------
71+
72+
| The ``cluster.apply()`` function applies a Ray Cluster in the given namespace. If the cluster already exists, it is updated.
73+
| If it does not exist it is created.
74+
6975
cluster.down()
7076
--------------
7177

src/codeflare_sdk/ray/cluster/cluster.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
from kubernetes.client.rest import ApiException
6060
import warnings
6161

62+
CF_SDK_FIELD_MANAGER = "codeflare-sdk"
63+
6264

6365
class Cluster:
6466
"""
@@ -89,11 +91,9 @@ def __init__(self, config: ClusterConfiguration):
8991
cluster_up_down_buttons(self)
9092

9193
def get_dynamic_client(self): # pragma: no cover
92-
"""Return a dynamic client, optionally mocked in tests."""
9394
return DynamicClient(get_api_client())
9495

9596
def config_check(self):
96-
"""Return a dynamic client, optionally mocked in tests."""
9797
return config_check()
9898

9999
@property
@@ -201,7 +201,7 @@ def apply(self, force=False):
201201
crds = self.get_dynamic_client().resources
202202
if self.config.appwrapper:
203203
api_version = "workload.codeflare.dev/v1beta2"
204-
api_instance = crds.get(api_version, kind="AppWrapper")
204+
api_instance = crds.get(api_version=api_version, kind="AppWrapper")
205205
# defaulting body to resource_yaml
206206
body = self.resource_yaml
207207
if self.config.write_to_file:
@@ -210,6 +210,7 @@ def apply(self, force=False):
210210
aw = yaml.load(f, Loader=yaml.FullLoader)
211211
body = aw
212212
api_instance.server_side_apply(
213+
field_manager=CF_SDK_FIELD_MANAGER,
213214
group="workload.codeflare.dev",
214215
version="v1beta2",
215216
namespace=namespace,
@@ -218,9 +219,14 @@ def apply(self, force=False):
218219
)
219220
print(f"AppWrapper: '{name}' has successfully been created")
220221
else:
221-
api_instance = crds.get(api_version="ray.io/v1", kind="RayCluster")
222-
self._component_resources_apply(namespace, api_instance)
222+
api_version = "ray.io/v1"
223+
api_instance = crds.get(api_version=api_version, kind="RayCluster")
224+
self._component_resources_apply(
225+
namespace=namespace, api_instance=api_instance
226+
)
223227
print(f"Ray Cluster: '{name}' has successfully been applied")
228+
except AttributeError as e:
229+
raise RuntimeError(f"Failed to initialize DynamicClient: {e}")
224230
except Exception as e: # pragma: no cover
225231
return _kube_api_error_handling(e)
226232

@@ -806,7 +812,7 @@ def _apply_resources(
806812
yamls, namespace: str, api_instance: client.CustomObjectsApi, force=False
807813
):
808814
api_instance.server_side_apply(
809-
field_manager="cluster-manager",
815+
field_manager=CF_SDK_FIELD_MANAGER,
810816
group="ray.io",
811817
version="v1",
812818
namespace=namespace,

0 commit comments

Comments
 (0)