1
+ from argparse import Namespace
1
2
from os import stat
2
3
from typing import List , Optional , Tuple
4
+ from unicodedata import name
3
5
4
6
import openshift as oc
5
7
@@ -18,6 +20,7 @@ def __init__(self, config: ClusterConfiguration):
18
20
19
21
def create_app_wrapper (self ):
20
22
name = self .config .name
23
+ namespace = self .config .namespace
21
24
min_cpu = self .config .min_cpus
22
25
max_cpu = self .config .max_cpus
23
26
min_memory = self .config .min_memory
@@ -29,21 +32,23 @@ def create_app_wrapper(self):
29
32
instascale = self .config .instascale
30
33
instance_types = self .config .machine_types
31
34
env = self .config .envs
32
- return generate_appwrapper (name = name , min_cpu = min_cpu , max_cpu = max_cpu , min_memory = min_memory ,
35
+ return generate_appwrapper (name = name , namespace = namespace , min_cpu = min_cpu , max_cpu = max_cpu , min_memory = min_memory ,
33
36
max_memory = max_memory , gpu = gpu , workers = workers , template = template ,
34
37
image = image , instascale = instascale , instance_types = instance_types , env = env )
35
38
36
- # creates a new cluster with the provided or default spec
37
- def up (self , namespace = 'default' ):
39
+ # creates a new cluster with the provided or default spec
40
+ def up (self ):
41
+ namespace = self .config .namespace
38
42
with oc .project (namespace ):
39
43
oc .invoke ("apply" , ["-f" , self .app_wrapper_yaml ])
40
44
41
- def down (self , namespace = 'default' ):
45
+ def down (self ):
46
+ namespace = self .config .namespace
42
47
with oc .project (namespace ):
43
48
oc .invoke ("delete" , ["AppWrapper" , self .app_wrapper_name ])
44
49
45
50
def status (self , print_to_console = True ):
46
- cluster = _ray_cluster_status (self .config .name )
51
+ cluster = _ray_cluster_status (self .config .name , self . config . namespace )
47
52
if cluster :
48
53
#overriding the number of gpus with requested
49
54
cluster .worker_gpu = self .config .gpu
@@ -55,19 +60,19 @@ def status(self, print_to_console=True):
55
60
pretty_print .print_no_resources_found ()
56
61
return None
57
62
58
- def cluster_uri (self , namespace = 'default' ):
59
- return f'ray://{ self .config .name } -head-svc.{ namespace } .svc:10001'
63
+ def cluster_uri (self ):
64
+ return f'ray://{ self .config .name } -head-svc.{ self . config . namespace } .svc:10001'
60
65
61
- def cluster_dashboard_uri (self , namespace = 'default' ):
62
- return f'http://{ self .config .name } -head-svc.{ namespace } .svc:8265'
66
+ def cluster_dashboard_uri (self ):
67
+ return f'http://{ self .config .name } -head-svc.{ self . config . namespace } .svc:8265'
63
68
64
69
65
70
# checks whether the ray cluster is ready
66
71
def is_ready (self , print_to_console = True ):
67
72
ready = False
68
73
status = CodeFlareClusterStatus .UNKNOWN
69
74
# check the app wrapper status
70
- appwrapper = _app_wrapper_status (self .config .name )
75
+ appwrapper = _app_wrapper_status (self .config .name , self . config . namespace )
71
76
if appwrapper :
72
77
if appwrapper .status in [AppWrapperStatus .RUNNING , AppWrapperStatus .COMPLETED , AppWrapperStatus .RUNNING_HOLD_COMPLETION ]:
73
78
ready = False
@@ -84,7 +89,7 @@ def is_ready(self, print_to_console=True):
84
89
return ready , status # no need to check the ray status since still in queue
85
90
86
91
# check the ray cluster status
87
- cluster = _ray_cluster_status (self .config .name )
92
+ cluster = _ray_cluster_status (self .config .name , self . config . namespace )
88
93
if cluster :
89
94
if cluster .status == RayClusterStatus .READY :
90
95
ready = True
@@ -99,16 +104,19 @@ def is_ready(self, print_to_console=True):
99
104
pretty_print .print_clusters ([cluster ])
100
105
return status , ready
101
106
107
+ def get_current_namespace ():
108
+ namespace = oc .invoke ("project" ,["-q" ]).actions ()[0 ].out .strip ()
109
+ return namespace
102
110
103
- def list_all_clusters (print_to_console = True ):
104
- clusters = _get_ray_clusters ()
111
+ def list_all_clusters (namespace , print_to_console = True ):
112
+ clusters = _get_ray_clusters (namespace )
105
113
if print_to_console :
106
114
pretty_print .print_clusters (clusters )
107
115
return clusters
108
116
109
117
110
- def list_all_queued (print_to_console = True ):
111
- app_wrappers = _get_app_wrappers (filter = [AppWrapperStatus .RUNNING , AppWrapperStatus .PENDING ])
118
+ def list_all_queued (namespace , print_to_console = True ):
119
+ app_wrappers = _get_app_wrappers ( namespace , filter = [AppWrapperStatus .RUNNING , AppWrapperStatus .PENDING ])
112
120
if print_to_console :
113
121
pretty_print .print_app_wrappers_status (app_wrappers )
114
122
return app_wrappers
@@ -151,7 +159,7 @@ def _get_ray_clusters(namespace='default') -> List[RayCluster]:
151
159
152
160
153
161
154
- def _get_app_wrappers (filter : List [ AppWrapperStatus ], namespace = 'default' ) -> List [AppWrapper ]:
162
+ def _get_app_wrappers (namespace = 'default' , filter = List [ AppWrapperStatus ] ) -> List [AppWrapper ]:
155
163
list_of_app_wrappers = []
156
164
157
165
with oc .project (namespace ), oc .timeout (10 * 60 ):
0 commit comments