Skip to content

Commit f8238b2

Browse files
committed
refactor: refactor creation of ray cluster/appwrapper
Signed-off-by: Bobbins228 <[email protected]>
1 parent 261da3f commit f8238b2

12 files changed

+1494
-718
lines changed

src/codeflare_sdk/cluster/cluster.py

+127-159
Large diffs are not rendered by default.

src/codeflare_sdk/cluster/config.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,16 @@ class ClusterConfiguration:
4747
Attributes:
4848
- name: The name of the cluster.
4949
- namespace: The namespace in which the cluster should be created.
50-
- head_info: A list of strings containing information about the head node.
5150
- head_cpus: The number of CPUs to allocate to the head node.
5251
- head_memory: The amount of memory to allocate to the head node.
5352
- head_gpus: The number of GPUs to allocate to the head node. (Deprecated, use head_extended_resource_requests)
5453
- head_extended_resource_requests: A dictionary of extended resource requests for the head node. ex: {"nvidia.com/gpu": 1}
55-
- machine_types: A list of machine types to use for the cluster.
5654
- min_cpus: The minimum number of CPUs to allocate to each worker.
5755
- max_cpus: The maximum number of CPUs to allocate to each worker.
5856
- num_workers: The number of workers to create.
5957
- min_memory: The minimum amount of memory to allocate to each worker.
6058
- max_memory: The maximum amount of memory to allocate to each worker.
6159
- num_gpus: The number of GPUs to allocate to each worker. (Deprecated, use worker_extended_resource_requests)
62-
- template: The path to the template file to use for the cluster.
6360
- appwrapper: A boolean indicating whether to use an AppWrapper.
6461
- envs: A dictionary of environment variables to set for the cluster.
6562
- image: The image to use for the cluster.
@@ -74,14 +71,10 @@ class ClusterConfiguration:
7471

7572
name: str
7673
namespace: Optional[str] = None
77-
head_info: List[str] = field(default_factory=list)
7874
head_cpus: Union[int, str] = 2
7975
head_memory: Union[int, str] = 8
8076
head_gpus: Optional[int] = None # Deprecating
8177
head_extended_resource_requests: Dict[str, int] = field(default_factory=dict)
82-
machine_types: List[str] = field(
83-
default_factory=list
84-
) # ["m4.xlarge", "g4dn.xlarge"]
8578
worker_cpu_requests: Union[int, str] = 1
8679
worker_cpu_limits: Union[int, str] = 1
8780
min_cpus: Optional[Union[int, str]] = None # Deprecating
@@ -92,10 +85,9 @@ class ClusterConfiguration:
9285
min_memory: Optional[Union[int, str]] = None # Deprecating
9386
max_memory: Optional[Union[int, str]] = None # Deprecating
9487
num_gpus: Optional[int] = None # Deprecating
95-
template: str = f"{dir}/templates/base-template.yaml"
9688
appwrapper: bool = False
9789
envs: Dict[str, str] = field(default_factory=dict)
98-
image: str = ""
90+
image: str = "quay.io/rhoai/ray:2.23.0-py39-cu121"
9991
image_pull_secrets: List[str] = field(default_factory=list)
10092
write_to_file: bool = False
10193
verify_tls: bool = True

src/codeflare_sdk/models/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from .v1_head_group_spec import V1HeadGroupSpec
2+
from .v1_worker_group_spec import V1WorkerGroupSpec
3+
from .v1_raycluster import V1RayCluster
4+
from .v1_raycluster_spec import V1RayClusterSpec
5+
from .v1_scale_strategy import V1ScaleStrategy
6+
from .v1_autoscaler_options import V1AutoScalerOptions
7+
8+
from importlib.metadata import version, PackageNotFoundError
9+
10+
try:
11+
__version__ = version("codeflare-sdk") # use metadata associated with built package
12+
13+
except PackageNotFoundError:
14+
__version__ = "v0.0.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
import pprint
2+
3+
import six
4+
5+
6+
class V1AutoScalerOptions(object): # pragma: no cover
7+
openapi_types = {
8+
"resources": "V1ResourceRequirements",
9+
"image": "str",
10+
"imagePullPolicy": "str",
11+
"securityContext": "V1SecurityContext",
12+
"idleTimeoutSeconds": "int32",
13+
"upscalingMode": "str",
14+
"env": "List[V1EnvVar]",
15+
"envFrom": "List[V1EnvFromSource]",
16+
"volumeMounts": "List[V1VolumeMount]",
17+
}
18+
19+
attribute_map = {
20+
"resources": "resources",
21+
"image": "image",
22+
"imagePullPolicy": "imagePullPolicy",
23+
"securityContext": "securityContext",
24+
"idleTimeoutSeconds": "idleTimeoutSeconds",
25+
"upscalingMode": "upscalingMode",
26+
"env": "env",
27+
"envFrom": "envFrom",
28+
"volumeMounts": "volumeMounts",
29+
}
30+
31+
def __init__(
32+
self,
33+
resources=None,
34+
image=None,
35+
imagePullPolicy=None,
36+
securityContext=None,
37+
idleTimeoutSeconds=None,
38+
upscalingMode=None,
39+
env=None,
40+
envFrom=None,
41+
volumeMounts=None,
42+
):
43+
self._resources = None
44+
self._image = None
45+
self._imagePullPolicy = None
46+
self._securityContext = None
47+
self._idleTimeoutSeconds = None
48+
self._upscalingMode = None
49+
self._env = None
50+
self._envFrom = None
51+
self._volumeMounts = None
52+
53+
if resources is not None:
54+
self._resources = resources
55+
if image is not None:
56+
self._image = image
57+
if imagePullPolicy is not None:
58+
self._imagePullPolicy = imagePullPolicy
59+
if securityContext is not None:
60+
self._securityContext = securityContext
61+
if idleTimeoutSeconds is not None:
62+
self._idleTimeoutSeconds = idleTimeoutSeconds
63+
if upscalingMode is not None:
64+
self._upscalingMode = upscalingMode
65+
if env is not None:
66+
self._env = env
67+
if envFrom is not None:
68+
self._envFrom = envFrom
69+
if volumeMounts is not None:
70+
self._volumeMounts = volumeMounts
71+
72+
@property
73+
def resources(self):
74+
return self._resources
75+
76+
@resources.setter
77+
def resources(self, resources):
78+
self._resources = resources
79+
80+
@property
81+
def image(self):
82+
return self._image
83+
84+
@image.setter
85+
def image(self, image):
86+
self._image = image
87+
88+
@property
89+
def imagePullPolicy(self):
90+
return self._imagePullPolicy
91+
92+
@imagePullPolicy.setter
93+
def imagePullPolicy(self, imagePullPolicy):
94+
self._imagePullPolicy = imagePullPolicy
95+
96+
@property
97+
def securityContext(self):
98+
return self._securityContext
99+
100+
@securityContext.setter
101+
def securityContext(self, securityContext):
102+
self._securityContext = securityContext
103+
104+
@property
105+
def idleTimeoutSeconds(self):
106+
return self._idleTimeoutSeconds
107+
108+
@idleTimeoutSeconds.setter
109+
def idleTimeoutSeconds(self, idleTimeoutSeconds):
110+
self._idleTimeoutSeconds = idleTimeoutSeconds
111+
112+
@property
113+
def upscalingMode(self):
114+
return self._upscalingMode
115+
116+
@upscalingMode.setter
117+
def upscalingMode(self, upscalingMode):
118+
self._upscalingMode = upscalingMode
119+
120+
@property
121+
def env(self):
122+
return self._env
123+
124+
@env.setter
125+
def env(self, env):
126+
self._env = env
127+
128+
@property
129+
def envFrom(self):
130+
return self._envFrom
131+
132+
@envFrom.setter
133+
def envFrom(self, envFrom):
134+
self._envFrom = envFrom
135+
136+
@property
137+
def volumeMounts(self):
138+
return self._volumeMounts
139+
140+
@volumeMounts.setter
141+
def volumeMounts(self, volumeMounts):
142+
self._volumeMounts = volumeMounts
143+
144+
def to_dict(self):
145+
"""Returns the model properties as a dict"""
146+
result = {}
147+
148+
for attr, _ in six.iteritems(self.openapi_types):
149+
value = getattr(self, attr)
150+
if isinstance(value, list):
151+
result[attr] = list(
152+
map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value)
153+
)
154+
elif hasattr(value, "to_dict"):
155+
result[attr] = value.to_dict()
156+
elif isinstance(value, dict):
157+
result[attr] = dict(
158+
map(
159+
lambda item: (item[0], item[1].to_dict())
160+
if hasattr(item[1], "to_dict")
161+
else item,
162+
value.items(),
163+
)
164+
)
165+
else:
166+
result[attr] = value
167+
168+
return result
169+
170+
def to_str(self):
171+
"""Returns the string representation of the model"""
172+
return pprint.pformat(self.to_dict())
173+
174+
def __repr__(self):
175+
"""For `print` and `pprint`"""
176+
return self.to_str()
177+
178+
def __eq__(self, other):
179+
"""Returns true if both objects are equal"""
180+
if not isinstance(other, V1AutoScalerOptions):
181+
return False
182+
183+
return self.to_dict() == other.to_dict()
184+
185+
def __ne__(self, other):
186+
"""Returns true if both objects are not equal"""
187+
if not isinstance(other, V1AutoScalerOptions):
188+
return True
189+
190+
return self.to_dict() != other.to_dict()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import pprint
2+
3+
import six
4+
5+
6+
class V1HeadGroupSpec(object): # pragma: no cover
7+
openapi_types = {
8+
"serviceType": "str",
9+
"headService": "str",
10+
"enableIngress": "bool",
11+
"rayStartParams": "Dict[str, str]",
12+
"template": "V1PodTemplateSpec",
13+
}
14+
15+
attribute_map = {
16+
"serviceType": "serviceType",
17+
"headService": "headService",
18+
"enableIngress": "enableIngress",
19+
"rayStartParams": "rayStartParams",
20+
"template": "template",
21+
}
22+
23+
def __init__(
24+
self,
25+
serviceType=None,
26+
headService=None,
27+
enableIngress=None,
28+
rayStartParams=None,
29+
template=None,
30+
):
31+
self._serviceType = None
32+
self._headService = None
33+
self._enableIngress = None
34+
self._rayStartParams = None
35+
self._template = None
36+
37+
if serviceType is not None:
38+
self._serviceType = serviceType
39+
if headService is not None:
40+
self._headService = headService
41+
if enableIngress is not None:
42+
self._enableIngress = enableIngress
43+
if rayStartParams is not None:
44+
self._rayStartParams = rayStartParams
45+
if template is not None:
46+
self._template = template
47+
48+
@property
49+
def serviceType(self):
50+
return self._serviceType
51+
52+
@serviceType.setter
53+
def serviceType(self, serviceType):
54+
self._serviceType = serviceType
55+
56+
@property
57+
def headService(self):
58+
return self._headService
59+
60+
@headService.setter
61+
def headService(self, headService):
62+
self._headService = headService
63+
64+
@property
65+
def enableIngress(self):
66+
return self._enableIngress
67+
68+
@enableIngress.setter
69+
def enableIngress(self, enableIngress):
70+
self._enableIngress = enableIngress
71+
72+
@property
73+
def rayStartParams(self):
74+
return self._rayStartParams
75+
76+
@rayStartParams.setter
77+
def rayStartParams(self, rayStartParams):
78+
self._rayStartParams = rayStartParams
79+
80+
@property
81+
def template(self):
82+
return self._template
83+
84+
@template.setter
85+
def template(self, template):
86+
self._template = template
87+
88+
def to_dict(self):
89+
"""Returns the model properties as a dict"""
90+
result = {}
91+
92+
for attr, _ in six.iteritems(self.openapi_types):
93+
value = getattr(self, attr)
94+
if isinstance(value, list):
95+
result[attr] = list(
96+
map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value)
97+
)
98+
elif hasattr(value, "to_dict"):
99+
result[attr] = value.to_dict()
100+
elif isinstance(value, dict):
101+
result[attr] = dict(
102+
map(
103+
lambda item: (item[0], item[1].to_dict())
104+
if hasattr(item[1], "to_dict")
105+
else item,
106+
value.items(),
107+
)
108+
)
109+
else:
110+
result[attr] = value
111+
112+
return result
113+
114+
def to_str(self):
115+
"""Returns the string representation of the model"""
116+
return pprint.pformat(self.to_dict())
117+
118+
def __repr__(self):
119+
"""For `print` and `pprint`"""
120+
return self.to_str()
121+
122+
def __eq__(self, other):
123+
"""Returns true if both objects are equal"""
124+
if not isinstance(other, V1HeadGroupSpec):
125+
return False
126+
127+
return self.to_dict() == other.to_dict()
128+
129+
def __ne__(self, other):
130+
"""Returns true if both objects are not equal"""
131+
if not isinstance(other, V1HeadGroupSpec):
132+
return True
133+
134+
return self.to_dict() != other.to_dict()

0 commit comments

Comments
 (0)