@@ -61,38 +61,25 @@ def __init__(self, config: ClusterConfiguration):
6161 self .app_wrapper_yaml = self .create_app_wrapper ()
6262 self .app_wrapper_name = self .app_wrapper_yaml .split ("." )[0 ]
6363
64- def evaluate_config (self ):
65- if not self .evaluate_dispatch_priority ():
66- return False
67- else :
68- return True
69-
7064 def evaluate_dispatch_priority (self ):
7165 priority_class = self .config .dispatch_priority
72- if priority_class is None :
73- return True
74- else :
75- try :
76- config_check ()
77- api_instance = client .CustomObjectsApi (api_config_handler ())
78- priority_classes = api_instance .list_cluster_custom_object (
79- group = "scheduling.k8s.io" ,
80- version = "v1" ,
81- plural = "priorityclasses" ,
82- )
83- available_priority_classes = [
84- i ["metadata" ]["name" ] for i in priority_classes ["items" ]
85- ]
86- except Exception as e : # pragma: no cover
87- return _kube_api_error_handling (e )
88-
89- if priority_class in available_priority_classes :
90- return True
91- else :
92- print (
93- f"Priority class { priority_class } is not available in the cluster"
94- )
95- return False
66+
67+ try :
68+ config_check ()
69+ api_instance = client .CustomObjectsApi (api_config_handler ())
70+ priority_classes = api_instance .list_cluster_custom_object (
71+ group = "scheduling.k8s.io" ,
72+ version = "v1" ,
73+ plural = "priorityclasses" ,
74+ )
75+ except Exception as e : # pragma: no cover
76+ return _kube_api_error_handling (e )
77+
78+ for pc in priority_classes ["items" ]:
79+ if pc ["metadata" ]["name" ] == priority_class :
80+ return pc ["value" ]
81+ print (f"Priority class { priority_class } is not available in the cluster" )
82+ return None
9683
9784 def create_app_wrapper (self ):
9885 """
@@ -109,6 +96,16 @@ def create_app_wrapper(self):
10996 f"Namespace { self .config .namespace } is of type { type (self .config .namespace )} . Check your Kubernetes Authentication."
11097 )
11198
99+ # Before attempting to create the cluster AW, let's evaluate the ClusterConfig
100+ if self .config .dispatch_priority :
101+ priority_val = self .evaluate_dispatch_priority ()
102+ if priority_val == None :
103+ raise ValueError (
104+ "Invalid Cluster Configuration, AppWrapper not generated"
105+ )
106+ else :
107+ priority_val = None
108+
112109 name = self .config .name
113110 namespace = self .config .namespace
114111 min_cpu = self .config .min_cpus
@@ -142,6 +139,7 @@ def create_app_wrapper(self):
142139 local_interactive = local_interactive ,
143140 image_pull_secrets = image_pull_secrets ,
144141 dispatch_priority = dispatch_priority ,
142+ priority_val = priority_val ,
145143 )
146144
147145 # creates a new cluster with the provided or default spec
@@ -150,12 +148,6 @@ def up(self):
150148 Applies the AppWrapper yaml, pushing the resource request onto
151149 the MCAD queue.
152150 """
153-
154- # Before attempting to bring up the cluster let's evaluate the ClusterConfig
155- if not self .evaluate_config ():
156- print ("Invalid Cluster Configuration" )
157- return False
158-
159151 namespace = self .config .namespace
160152 try :
161153 config_check ()
0 commit comments