@@ -250,7 +250,18 @@ def __repr__(self):
250
250
251
251
def configure (
252
252
self ,
253
- om : MongoDBOpsManager ,
253
+ om : Optional [MongoDBOpsManager ],
254
+ project_name : str ,
255
+ api_client : Optional [client .ApiClient ] = None ,
256
+ ) -> MongoDB :
257
+ if om is not None :
258
+ return self .configure_ops_manager (om , project_name , api_client = api_client )
259
+ else :
260
+ return self .configure_cloud_qa (project_name , api_client = api_client )
261
+
262
+ def configure_ops_manager (
263
+ self ,
264
+ om : Optional [MongoDBOpsManager ],
254
265
project_name : str ,
255
266
api_client : Optional [client .ApiClient ] = None ,
256
267
) -> MongoDB :
@@ -267,6 +278,37 @@ def configure(
267
278
self ["spec" ]["credentials" ] = om .api_key_secret (self .namespace , api_client = api_client )
268
279
return self
269
280
281
+ def configure_cloud_qa (
282
+ self ,
283
+ project_name ,
284
+ src_project_config_map_name : str = None ,
285
+ api_client : Optional [client .ApiClient ] = None ,
286
+ ) -> MongoDB :
287
+ if "opsManager" in self ["spec" ]:
288
+ del self ["spec" ]["opsManager" ]
289
+
290
+ ensure_nested_objects (self , ["spec" , "cloudManager" , "configMapRef" ])
291
+
292
+ if src_project_config_map_name is None and "cloudManager" in self ["spec" ]:
293
+ src_project_config_map_name = self ["spec" ]["cloudManager" ]["configMapRef" ]["name" ]
294
+
295
+ try :
296
+ src_cm = read_configmap (self .namespace , src_project_config_map_name , api_client = api_client )
297
+ except client .ApiException as e :
298
+ if e .status == 404 :
299
+ logger .debug ("project config map is not specified, trying my-project as the source" )
300
+ src_cm = read_configmap (self .namespace , "my-project" , api_client = api_client )
301
+ else :
302
+ raise e
303
+
304
+ new_project_config_map_name = f"{ self .name } -project-config"
305
+ self ["spec" ]["cloudManager" ]["configMapRef" ]["name" ] = new_project_config_map_name
306
+
307
+ src_cm .update ({"projectName" : f"{ self .namespace } -{ project_name } " })
308
+ create_or_update_configmap (self .namespace , new_project_config_map_name , src_cm , api_client = api_client )
309
+
310
+ return self
311
+
270
312
def configure_backup (self , mode : str = "enabled" ) -> MongoDB :
271
313
ensure_nested_objects (self , ["spec" , "backup" ])
272
314
self ["spec" ]["backup" ]["mode" ] = mode
0 commit comments