7
7
from typing import Dict , List , Optional
8
8
9
9
import semver
10
+ from kubernetes .client import ApiException
11
+
10
12
from kubeobject import CustomObject
11
13
from kubernetes import client
12
14
from kubetester import create_or_update_configmap , read_configmap
37
39
38
40
39
41
class MongoDB (CustomObject , MongoDBCommon ):
40
- # project name set when configure method is called
41
- om_project_name : Optional [str ]
42
-
43
42
def __init__ (self , * args , ** kwargs ):
44
43
with_defaults = {
45
44
"plural" : "mongodb" ,
@@ -48,7 +47,6 @@ def __init__(self, *args, **kwargs):
48
47
"version" : "v1" ,
49
48
}
50
49
with_defaults .update (kwargs )
51
- self .om_project_name = None
52
50
super (MongoDB , self ).__init__ (* args , ** with_defaults )
53
51
54
52
@classmethod
@@ -261,14 +259,12 @@ def configure_ops_manager(
261
259
# then the secret needs to be copied there manually
262
260
self ["spec" ]["credentials" ] = om .api_key_secret (self .namespace , api_client = api_client )
263
261
264
- self .om_project_name = project_name
265
-
266
262
return self
267
263
268
264
def configure_cloud_qa (
269
265
self ,
270
266
project_name ,
271
- src_project_config_map_name : str = None ,
267
+ src_project_config_map_name : Optional [ str ] = None ,
272
268
api_client : Optional [client .ApiClient ] = None ,
273
269
) -> MongoDB :
274
270
if "opsManager" in self ["spec" ]:
@@ -280,27 +276,16 @@ def configure_cloud_qa(
280
276
ensure_nested_objects (self , ["spec" , "cloudManager" , "configMapRef" ])
281
277
self ["spec" ]["cloudManager" ]["configMapRef" ]["name" ] = new_project_config_map_name
282
278
279
+ # we update the project name by adding a namespace prefix to ensure uniqueness in shared cloud-qa projects
280
+ # the namespace prefix is not added if we run the test against
283
281
src_cm .update ({"projectName" : f"{ self .namespace } -{ project_name } " })
284
282
create_or_update_configmap (self .namespace , new_project_config_map_name , src_cm , api_client = api_client )
285
283
286
284
return self
287
285
288
- def get_project_config_map (self , api_client , src_project_config_map_name ):
289
- if src_project_config_map_name is None and "cloudManager" in self ["spec" ]:
290
- src_project_config_map_name = self ["spec" ]["cloudManager" ]["configMapRef" ]["name" ]
291
- else :
292
- # my-project cm and my-credentials secret are created by scripts/evergreen/e2e/configure_operator.sh
293
- src_project_config_map_name = "my-project"
294
- try :
295
- src_cm = read_configmap (self .namespace , src_project_config_map_name , api_client = api_client )
296
- except client .ApiException as e :
297
- if e .status == 404 :
298
- logger .debug ("project config map is not specified, trying my-project as the source" )
299
- src_cm = read_configmap (self .namespace , "my-project" , api_client = api_client )
300
- else :
301
- raise e
302
-
303
- return src_cm
286
+ def get_om_project_name (self ) -> str :
287
+ project_cm = self .read_configmap ()
288
+ return project_cm ["projectName" ]
304
289
305
290
def configure_backup (self , mode : str = "enabled" ) -> MongoDB :
306
291
ensure_nested_objects (self , ["spec" , "backup" ])
@@ -488,8 +473,8 @@ def get_om_tester(self) -> OMTester:
488
473
489
474
def get_automation_config_tester (self , ** kwargs ):
490
475
"""This is just a shortcut for getting automation config tester for replica set"""
491
- if "group_name" not in kwargs and self . om_project_name is not None :
492
- kwargs ["group_name" ] = self .om_project_name
476
+ if "group_name" not in kwargs :
477
+ kwargs ["group_name" ] = self .get_om_project_name ()
493
478
return self .get_om_tester ().get_automation_config_tester (** kwargs )
494
479
495
480
def get_external_domain (self ):
0 commit comments