@@ -93,6 +93,39 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
9393 self.app_wrapper_yaml = self.create_app_wrapper()
9494 self.app_wrapper_name = self.app_wrapper_yaml.split(".")[0]
9595
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+
96129 def create_app_wrapper(self):
97130 """
98131 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>
123156 env = self.config.envs
124157 local_interactive = self.config.local_interactive
125158 image_pull_secrets = self.config.image_pull_secrets
159+ dispatch_priority = self.config.dispatch_priority
126160 return generate_appwrapper(
127161 name=name,
128162 namespace=namespace,
@@ -139,6 +173,7 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
139173 env=env,
140174 local_interactive=local_interactive,
141175 image_pull_secrets=image_pull_secrets,
176+ dispatch_priority=dispatch_priority,
142177 )
143178
144179 # 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>
147182 Applies the AppWrapper yaml, pushing the resource request onto
148183 the MCAD queue.
149184 """
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+
150191 namespace = self.config.namespace
151192 try:
152193 config_check()
@@ -787,6 +828,39 @@ <h2 class="section-title" id="header-classes">Classes</h2>
787828 self.app_wrapper_yaml = self.create_app_wrapper()
788829 self.app_wrapper_name = self.app_wrapper_yaml.split(".")[0]
789830
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+
790864 def create_app_wrapper(self):
791865 """
792866 Called upon cluster object creation, creates an AppWrapper yaml based on
@@ -817,6 +891,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
817891 env = self.config.envs
818892 local_interactive = self.config.local_interactive
819893 image_pull_secrets = self.config.image_pull_secrets
894+ dispatch_priority = self.config.dispatch_priority
820895 return generate_appwrapper(
821896 name=name,
822897 namespace=namespace,
@@ -833,6 +908,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
833908 env=env,
834909 local_interactive=local_interactive,
835910 image_pull_secrets=image_pull_secrets,
911+ dispatch_priority=dispatch_priority,
836912 )
837913
838914 # creates a new cluster with the provided or default spec
@@ -841,6 +917,12 @@ <h2 class="section-title" id="header-classes">Classes</h2>
841917 Applies the AppWrapper yaml, pushing the resource request onto
842918 the MCAD queue.
843919 """
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+
844926 namespace = self.config.namespace
845927 try:
846928 config_check()
@@ -1181,6 +1263,7 @@ <h3>Methods</h3>
11811263 env = self.config.envs
11821264 local_interactive = self.config.local_interactive
11831265 image_pull_secrets = self.config.image_pull_secrets
1266+ dispatch_priority = self.config.dispatch_priority
11841267 return generate_appwrapper(
11851268 name=name,
11861269 namespace=namespace,
@@ -1197,6 +1280,7 @@ <h3>Methods</h3>
11971280 env=env,
11981281 local_interactive=local_interactive,
11991282 image_pull_secrets=image_pull_secrets,
1283+ dispatch_priority=dispatch_priority,
12001284 )</ code > </ pre >
12011285</ details >
12021286</ dd >
@@ -1246,6 +1330,59 @@ <h3>Methods</h3>
12461330 return _kube_api_error_handling(e)</ code > </ pre >
12471331</ details >
12481332</ 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 >
12491386< dt id ="codeflare_sdk.cluster.cluster.Cluster.from_k8_cluster_object "> < code class ="name flex ">
12501387< span > def < span class ="ident "> from_k8_cluster_object</ span > </ span > (< span > rc)</ span >
12511388</ code > </ dt >
@@ -1486,6 +1623,12 @@ <h3>Methods</h3>
14861623 Applies the AppWrapper yaml, pushing the resource request onto
14871624 the MCAD queue.
14881625 """
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+
14891632 namespace = self.config.namespace
14901633 try:
14911634 config_check()
@@ -1570,6 +1713,8 @@ <h4><code><a title="codeflare_sdk.cluster.cluster.Cluster" href="#codeflare_sdk.
15701713< 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 >
15711714< li > < code > < a title ="codeflare_sdk.cluster.cluster.Cluster.details " href ="#codeflare_sdk.cluster.cluster.Cluster.details "> details</ a > </ code > </ li >
15721715< 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 >
15731718< 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 >
15741719< li > < code > < a title ="codeflare_sdk.cluster.cluster.Cluster.job_logs " href ="#codeflare_sdk.cluster.cluster.Cluster.job_logs "> job_logs</ a > </ code > </ li >
15751720< 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