@@ -93,6 +93,39 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
93
93
self.app_wrapper_yaml = self.create_app_wrapper()
94
94
self.app_wrapper_name = self.app_wrapper_yaml.split(".")[0]
95
95
96
+ def evaluate_config(self):
97
+ if not self.evaluate_dispatch_priority():
98
+ return False
99
+ else:
100
+ return True
101
+
102
+ def evaluate_dispatch_priority(self):
103
+ priority_class = self.config.dispatch_priority
104
+ if priority_class is None:
105
+ return True
106
+ else:
107
+ try:
108
+ config_check()
109
+ api_instance = client.CustomObjectsApi(api_config_handler())
110
+ priority_classes = api_instance.list_cluster_custom_object(
111
+ group="scheduling.k8s.io",
112
+ version="v1",
113
+ plural="priorityclasses",
114
+ )
115
+ available_priority_classes = [
116
+ i["metadata"]["name"] for i in priority_classes["items"]
117
+ ]
118
+ except Exception as e: # pragma: no cover
119
+ return _kube_api_error_handling(e)
120
+
121
+ if priority_class in available_priority_classes:
122
+ return True
123
+ else:
124
+ print(
125
+ f"Priority class {priority_class} is not available in the cluster"
126
+ )
127
+ return False
128
+
96
129
def create_app_wrapper(self):
97
130
"""
98
131
Called upon cluster object creation, creates an AppWrapper yaml based on
@@ -123,6 +156,7 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
123
156
env = self.config.envs
124
157
local_interactive = self.config.local_interactive
125
158
image_pull_secrets = self.config.image_pull_secrets
159
+ dispatch_priority = self.config.dispatch_priority
126
160
return generate_appwrapper(
127
161
name=name,
128
162
namespace=namespace,
@@ -139,6 +173,7 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
139
173
env=env,
140
174
local_interactive=local_interactive,
141
175
image_pull_secrets=image_pull_secrets,
176
+ dispatch_priority=dispatch_priority,
142
177
)
143
178
144
179
# creates a new cluster with the provided or default spec
@@ -147,6 +182,12 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
147
182
Applies the AppWrapper yaml, pushing the resource request onto
148
183
the MCAD queue.
149
184
"""
185
+
186
+ # Before attempting to bring up the cluster let's evaluate the ClusterConfig
187
+ if not self.evaluate_config():
188
+ print("Invalid Cluster Configuration")
189
+ return False
190
+
150
191
namespace = self.config.namespace
151
192
try:
152
193
config_check()
@@ -787,6 +828,39 @@ <h2 class="section-title" id="header-classes">Classes</h2>
787
828
self.app_wrapper_yaml = self.create_app_wrapper()
788
829
self.app_wrapper_name = self.app_wrapper_yaml.split(".")[0]
789
830
831
+ def evaluate_config(self):
832
+ if not self.evaluate_dispatch_priority():
833
+ return False
834
+ else:
835
+ return True
836
+
837
+ def evaluate_dispatch_priority(self):
838
+ priority_class = self.config.dispatch_priority
839
+ if priority_class is None:
840
+ return True
841
+ else:
842
+ try:
843
+ config_check()
844
+ api_instance = client.CustomObjectsApi(api_config_handler())
845
+ priority_classes = api_instance.list_cluster_custom_object(
846
+ group="scheduling.k8s.io",
847
+ version="v1",
848
+ plural="priorityclasses",
849
+ )
850
+ available_priority_classes = [
851
+ i["metadata"]["name"] for i in priority_classes["items"]
852
+ ]
853
+ except Exception as e: # pragma: no cover
854
+ return _kube_api_error_handling(e)
855
+
856
+ if priority_class in available_priority_classes:
857
+ return True
858
+ else:
859
+ print(
860
+ f"Priority class {priority_class} is not available in the cluster"
861
+ )
862
+ return False
863
+
790
864
def create_app_wrapper(self):
791
865
"""
792
866
Called upon cluster object creation, creates an AppWrapper yaml based on
@@ -817,6 +891,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
817
891
env = self.config.envs
818
892
local_interactive = self.config.local_interactive
819
893
image_pull_secrets = self.config.image_pull_secrets
894
+ dispatch_priority = self.config.dispatch_priority
820
895
return generate_appwrapper(
821
896
name=name,
822
897
namespace=namespace,
@@ -833,6 +908,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
833
908
env=env,
834
909
local_interactive=local_interactive,
835
910
image_pull_secrets=image_pull_secrets,
911
+ dispatch_priority=dispatch_priority,
836
912
)
837
913
838
914
# creates a new cluster with the provided or default spec
@@ -841,6 +917,12 @@ <h2 class="section-title" id="header-classes">Classes</h2>
841
917
Applies the AppWrapper yaml, pushing the resource request onto
842
918
the MCAD queue.
843
919
"""
920
+
921
+ # Before attempting to bring up the cluster let's evaluate the ClusterConfig
922
+ if not self.evaluate_config():
923
+ print("Invalid Cluster Configuration")
924
+ return False
925
+
844
926
namespace = self.config.namespace
845
927
try:
846
928
config_check()
@@ -1181,6 +1263,7 @@ <h3>Methods</h3>
1181
1263
env = self.config.envs
1182
1264
local_interactive = self.config.local_interactive
1183
1265
image_pull_secrets = self.config.image_pull_secrets
1266
+ dispatch_priority = self.config.dispatch_priority
1184
1267
return generate_appwrapper(
1185
1268
name=name,
1186
1269
namespace=namespace,
@@ -1197,6 +1280,7 @@ <h3>Methods</h3>
1197
1280
env=env,
1198
1281
local_interactive=local_interactive,
1199
1282
image_pull_secrets=image_pull_secrets,
1283
+ dispatch_priority=dispatch_priority,
1200
1284
)</ code > </ pre >
1201
1285
</ details >
1202
1286
</ dd >
@@ -1246,6 +1330,59 @@ <h3>Methods</h3>
1246
1330
return _kube_api_error_handling(e)</ code > </ pre >
1247
1331
</ details >
1248
1332
</ dd >
1333
+ < dt id ="codeflare_sdk.cluster.cluster.Cluster.evaluate_config "> < code class ="name flex ">
1334
+ < span > def < span class ="ident "> evaluate_config</ span > </ span > (< span > self)</ span >
1335
+ </ code > </ dt >
1336
+ < dd >
1337
+ < div class ="desc "> </ div >
1338
+ < details class ="source ">
1339
+ < summary >
1340
+ < span > Expand source code</ span >
1341
+ </ summary >
1342
+ < pre > < code class ="python "> def evaluate_config(self):
1343
+ if not self.evaluate_dispatch_priority():
1344
+ return False
1345
+ else:
1346
+ return True</ code > </ pre >
1347
+ </ details >
1348
+ </ dd >
1349
+ < dt id ="codeflare_sdk.cluster.cluster.Cluster.evaluate_dispatch_priority "> < code class ="name flex ">
1350
+ < span > def < span class ="ident "> evaluate_dispatch_priority</ span > </ span > (< span > self)</ span >
1351
+ </ code > </ dt >
1352
+ < dd >
1353
+ < div class ="desc "> </ div >
1354
+ < details class ="source ">
1355
+ < summary >
1356
+ < span > Expand source code</ span >
1357
+ </ summary >
1358
+ < pre > < code class ="python "> def evaluate_dispatch_priority(self):
1359
+ priority_class = self.config.dispatch_priority
1360
+ if priority_class is None:
1361
+ return True
1362
+ else:
1363
+ try:
1364
+ config_check()
1365
+ api_instance = client.CustomObjectsApi(api_config_handler())
1366
+ priority_classes = api_instance.list_cluster_custom_object(
1367
+ group="scheduling.k8s.io",
1368
+ version="v1",
1369
+ plural="priorityclasses",
1370
+ )
1371
+ available_priority_classes = [
1372
+ i["metadata"]["name"] for i in priority_classes["items"]
1373
+ ]
1374
+ except Exception as e: # pragma: no cover
1375
+ return _kube_api_error_handling(e)
1376
+
1377
+ if priority_class in available_priority_classes:
1378
+ return True
1379
+ else:
1380
+ print(
1381
+ f"Priority class {priority_class} is not available in the cluster"
1382
+ )
1383
+ return False</ code > </ pre >
1384
+ </ details >
1385
+ </ dd >
1249
1386
< dt id ="codeflare_sdk.cluster.cluster.Cluster.from_k8_cluster_object "> < code class ="name flex ">
1250
1387
< span > def < span class ="ident "> from_k8_cluster_object</ span > </ span > (< span > rc)</ span >
1251
1388
</ code > </ dt >
@@ -1486,6 +1623,12 @@ <h3>Methods</h3>
1486
1623
Applies the AppWrapper yaml, pushing the resource request onto
1487
1624
the MCAD queue.
1488
1625
"""
1626
+
1627
+ # Before attempting to bring up the cluster let's evaluate the ClusterConfig
1628
+ if not self.evaluate_config():
1629
+ print("Invalid Cluster Configuration")
1630
+ return False
1631
+
1489
1632
namespace = self.config.namespace
1490
1633
try:
1491
1634
config_check()
@@ -1570,6 +1713,8 @@ <h4><code><a title="codeflare_sdk.cluster.cluster.Cluster" href="#codeflare_sdk.
1570
1713
< li > < code > < a title ="codeflare_sdk.cluster.cluster.Cluster.create_app_wrapper " href ="#codeflare_sdk.cluster.cluster.Cluster.create_app_wrapper "> create_app_wrapper</ a > </ code > </ li >
1571
1714
< li > < code > < a title ="codeflare_sdk.cluster.cluster.Cluster.details " href ="#codeflare_sdk.cluster.cluster.Cluster.details "> details</ a > </ code > </ li >
1572
1715
< li > < code > < a title ="codeflare_sdk.cluster.cluster.Cluster.down " href ="#codeflare_sdk.cluster.cluster.Cluster.down "> down</ a > </ code > </ li >
1716
+ < li > < code > < a title ="codeflare_sdk.cluster.cluster.Cluster.evaluate_config " href ="#codeflare_sdk.cluster.cluster.Cluster.evaluate_config "> evaluate_config</ a > </ code > </ li >
1717
+ < li > < code > < a title ="codeflare_sdk.cluster.cluster.Cluster.evaluate_dispatch_priority " href ="#codeflare_sdk.cluster.cluster.Cluster.evaluate_dispatch_priority "> evaluate_dispatch_priority</ a > </ code > </ li >
1573
1718
< li > < code > < a title ="codeflare_sdk.cluster.cluster.Cluster.from_k8_cluster_object " href ="#codeflare_sdk.cluster.cluster.Cluster.from_k8_cluster_object "> from_k8_cluster_object</ a > </ code > </ li >
1574
1719
< li > < code > < a title ="codeflare_sdk.cluster.cluster.Cluster.job_logs " href ="#codeflare_sdk.cluster.cluster.Cluster.job_logs "> job_logs</ a > </ code > </ li >
1575
1720
< li > < code > < a title ="codeflare_sdk.cluster.cluster.Cluster.job_status " href ="#codeflare_sdk.cluster.cluster.Cluster.job_status "> job_status</ a > </ code > </ li >
0 commit comments