1818
1919class Config :
2020
21- def __init__ (self , cm_name , owner ):
21+ def __init__ (self , cm_name , owner , cm_namespace ):
2222 self .c = None
2323 self .c_data = None
2424 self .cm_name = cm_name
2525 self .owner = owner
26+ self .cm_namespace = cm_namespace
2627
2728 def lock (self ):
2829 # The lock function is used to avoid two isolate
@@ -40,15 +41,16 @@ def lock(self):
4041 time .sleep (random .random ())
4142 while True :
4243 try :
43- c = k8s .get_config_map (None , self .cm_name , "default" )
44+ c = k8s .get_config_map (None , self .cm_name , self . cm_namespace )
4445 owner = c .metadata .annotations ["Owner" ]
4546 if owner != "" :
4647 time .sleep (1 )
4748 continue
4849 else :
4950 c .metadata .annotations ["Owner" ] = self .owner
5051 try :
51- k8s .patch_config_map (None , self .cm_name , c , "default" )
52+ k8s .patch_config_map (None , self .cm_name ,
53+ c , self .cm_namespace )
5254 except K8sApiException as err :
5355 logging .error ("Error while retreiving configmap {}"
5456 .format (self .cm_name ))
@@ -73,7 +75,8 @@ def unlock(self):
7375 }
7476 clusterinit .update_configmap (configmap , self .cm_name , data )
7577 try :
76- k8s .patch_config_map (None , self .cm_name , configmap , "default" )
78+ k8s .patch_config_map (None , self .cm_name ,
79+ configmap , self .cm_namespace )
7780 except K8sApiException as err :
7881 logging .error ("Error while retreiving configmap {}"
7982 .format (self .cm_name ))
@@ -232,7 +235,7 @@ def as_dict(self):
232235 return result
233236
234237
235- def new (platform , excl_non_isolcpus , name ):
238+ def new (platform , excl_non_isolcpus , name , namespace ):
236239 # Creates the new CMK configuration for the node. It create a
237240 # configmap object and POSTs it to the K8s API Server
238241
@@ -243,20 +246,32 @@ def new(platform, excl_non_isolcpus, name):
243246 config = update_configmap_exclusive ("exclusive-non-isolcpus" ,
244247 platform , config )
245248 config = update_configmap_shared ("infra" , platform , config )
246-
247- configmap = k8sclient .V1ConfigMap ()
248249 data = {
249250 "config" : yaml .dump (config )
250251 }
251- clusterinit .update_configmap (configmap , name , data )
252-
253- try :
254- k8s .create_config_map (None , configmap , "default" )
255- except K8sApiException as err :
256- logging .error ("Exception when creating config map {}"
257- .format (name ))
258- logging .error (err .reason )
259- sys .exit (1 )
252+
253+ configmap = k8s .get_config_map (None , name , namespace )
254+
255+ if configmap is None :
256+ configmap = k8sclient .V1ConfigMap ()
257+ clusterinit .update_configmap (configmap , name , data )
258+
259+ try :
260+ k8s .create_config_map (None , configmap , namespace )
261+ except K8sApiException as err :
262+ logging .error ("Exception when creating config map {}"
263+ .format (name ))
264+ logging .error (err .reason )
265+ sys .exit (1 )
266+ else :
267+ clusterinit .update_configmap (configmap , name , data )
268+ try :
269+ k8s .patch_config_map (None , name , configmap , namespace )
270+ except K8sApiException as err :
271+ logging .error ("Error while patching configmap {}"
272+ .format (name ))
273+ logging .error (err .reason )
274+ sys .exit (1 )
260275
261276
262277def update_configmap_exclusive (pool_name , platform , config ):
0 commit comments