28
28
wait_for_operator_ready ,
29
29
)
30
30
from tests .opsmanager .om_ops_manager_backup import create_aws_secret , create_s3_bucket
31
- from tests .upgrades import downscale_operator_deployment
32
31
33
32
# See docs how to run this locally: https://wiki.corp.mongodb.com/display/MMS/E2E+Tests+Notes#E2ETestsNotes-OLMtests
34
33
35
34
# This test performs operator migration from the latest MEKO to MCK while having OM and MongoDB resources deployed.
36
- # It performs the following actions:
35
+ # It uses the uninstall-then-install approach since operatorhub.io and other catalogs
36
+ # do not allow cross-package upgrades with the "replaces" directive.
37
+ # The test performs the following actions:
37
38
# - deploy latest released MEKO operator using OLM
38
39
# - deploy OM
39
40
# - deploy backup-required MongoDB: oplog, s3, blockstore
40
41
# - deploy TLS-enabled sharded MongoDB
41
42
# - check everything is running
42
- # - upgrade the operator to the MCK version built from the current branch
43
+ # - uninstall MEKO operator by deleting Subscription and ClusterServiceVersion resources
44
+ # - install MCK operator using OLM with a fresh subscription
43
45
# - wait for resources to be rolling-updated due to updated stateful sets by the new operator
44
46
# - check everything is running and connectable
45
47
@@ -59,15 +61,13 @@ def catalog_source(namespace: str, version_id: str):
59
61
60
62
61
63
@fixture
62
- def subscription (namespace : str , catalog_source : CustomObject ):
64
+ def meko_subscription (namespace : str , catalog_source : CustomObject ):
63
65
"""
64
- Create subscription for the operator. The subscription is first created
65
- with the latest released version of MEKO operator.
66
- Later in the test, it will be updated to MCK.
66
+ Create subscription for the MEKO operator.
67
67
"""
68
68
static_value = get_default_architecture ()
69
69
return get_subscription_custom_object (
70
- "mongodb-enterprise-operator" ,
70
+ LEGACY_OPERATOR_NAME ,
71
71
namespace ,
72
72
{
73
73
"channel" : "stable" , # stable channel contains latest released operator in RedHat's certified repository
@@ -89,6 +89,33 @@ def subscription(namespace: str, catalog_source: CustomObject):
89
89
)
90
90
91
91
92
+ def get_mck_subscription_object (namespace : str , catalog_source : CustomObject ):
93
+ """
94
+ Create a subscription object for the MCK operator.
95
+ This is a separate function (not a fixture) so it can be called after uninstalling MEKO.
96
+ """
97
+ static_value = get_default_architecture ()
98
+ return get_subscription_custom_object (
99
+ OPERATOR_NAME ,
100
+ namespace ,
101
+ {
102
+ "channel" : "migration" ,
103
+ "name" : "mongodb-kubernetes" ,
104
+ "source" : catalog_source .name ,
105
+ "sourceNamespace" : namespace ,
106
+ "installPlanApproval" : "Automatic" ,
107
+ "config" : {
108
+ "env" : [
109
+ {"name" : "MANAGED_SECURITY_CONTEXT" , "value" : "false" },
110
+ {"name" : "OPERATOR_ENV" , "value" : "dev" },
111
+ {"name" : "MDB_DEFAULT_ARCHITECTURE" , "value" : static_value },
112
+ {"name" : "MDB_OPERATOR_TELEMETRY_SEND_ENABLED" , "value" : "false" },
113
+ ]
114
+ },
115
+ },
116
+ )
117
+
118
+
92
119
@fixture
93
120
def latest_released_meko_version ():
94
121
return get_latest_released_operator_version ("mongodb-enterprise" )
@@ -100,12 +127,10 @@ def test_meko_install_stable_operator_version(
100
127
version_id : str ,
101
128
latest_released_meko_version : str ,
102
129
catalog_source : CustomObject ,
103
- subscription : CustomObject ,
130
+ meko_subscription : CustomObject ,
104
131
):
105
- subscription .update ()
106
- wait_for_operator_ready (
107
- namespace , "mongodb-enterprise-operator" , f"mongodb-enterprise.v{ latest_released_meko_version } "
108
- )
132
+ meko_subscription .update ()
133
+ wait_for_operator_ready (namespace , LEGACY_OPERATOR_NAME , f"mongodb-enterprise.v{ latest_released_meko_version } " )
109
134
110
135
111
136
# install resources on the latest released version of the operator
@@ -344,59 +369,60 @@ def test_resources_in_running_state_before_upgrade(
344
369
mdb_sharded .assert_reaches_phase (Phase .Running )
345
370
346
371
347
- # upgrade the operator
372
+ # uninstall MEKO and install MCK operator instead
348
373
349
374
350
- @pytest .mark .e2e_olm_meko_operator_upgrade_with_resources
351
- def test_downscale_meko (namespace : str ):
352
- # Scale down the existing operator deployment to 0. This is needed as long as the
353
- # initial OLM deployment installs the MEKO operator.
354
- downscale_operator_deployment (deployment_name = LEGACY_OPERATOR_NAME , namespace = namespace )
375
+ def uninstall_meko_operator (namespace : str , meko_subscription : CustomObject ):
376
+ """Uninstall the MEKO operator by deleting Subscription and ClusterServiceVersion"""
377
+
378
+ # Load the subscription from API server
379
+ # so we can get CSV name from status
380
+ meko_subscription .load ()
381
+ csv_name = meko_subscription ["status" ]["installedCSV" ]
382
+
383
+ # Delete the subscription
384
+ meko_subscription .delete ()
385
+
386
+ # Delete ClusterServiceVersion
387
+ api_instance = kubernetes .client .CustomObjectsApi ()
388
+ api_instance .delete_namespaced_custom_object (
389
+ group = "operators.coreos.com" ,
390
+ version = "v1alpha1" ,
391
+ namespace = namespace ,
392
+ plural = "clusterserviceversions" ,
393
+ name = csv_name ,
394
+ )
355
395
356
396
357
397
@pytest .mark .e2e_olm_meko_operator_upgrade_with_resources
358
- def test_meko_operator_upgrade_to_mck (
398
+ def test_migrate_meko_to_mck_operator (
359
399
namespace : str ,
360
400
version_id : str ,
361
401
catalog_source : CustomObject ,
362
- subscription : CustomObject ,
402
+ meko_subscription : CustomObject ,
363
403
):
404
+ # Uninstall the MEKO operator
405
+ uninstall_meko_operator (namespace , meko_subscription )
406
+
364
407
current_operator_version = get_current_operator_version ()
365
408
incremented_operator_version = increment_patch_version (current_operator_version )
366
409
367
- # It is very likely that OLM will be doing a series of status updates during this time.
368
- # It's better to employ a retry mechanism and spin here for a while before failing.
369
- def update_subscription () -> bool :
370
- try :
371
- subscription .load ()
372
- # Update MEKO subscription to MCK
373
- subscription ["spec" ]["name" ] = "mongodb-kubernetes"
374
- # Migration channel contains operator build from the current branch,
375
- # with an upgrade path from the latest MEKO release.
376
- subscription ["spec" ]["channel" ] = "migration"
377
- subscription .update ()
378
- return True
379
- except kubernetes .client .ApiException as e :
380
- if e .status == 409 :
381
- return False
382
- else :
383
- raise e
384
-
385
- run_periodically (update_subscription , timeout = 100 , msg = "Subscription to be updated" )
410
+ # Create MCK subscription
411
+ mck_subscription = get_mck_subscription_object (namespace , catalog_source )
412
+ mck_subscription .update ()
386
413
387
414
wait_for_operator_ready (namespace , OPERATOR_NAME , f"mongodb-kubernetes.v{ incremented_operator_version } " )
388
415
389
416
390
417
@pytest .mark .e2e_olm_meko_operator_upgrade_with_resources
391
- def test_one_resources_not_in_running_state (ops_manager : MongoDBOpsManager , mdb_sharded : MongoDB ):
392
- # Wait for the first resource to become reconciling after operator upgrade.
393
- # Only then wait for all to not get a false positive when all resources are ready,
394
- # because the upgraded operator haven't started reconciling
418
+ def test_one_resource_not_in_running_state (ops_manager : MongoDBOpsManager ):
419
+ # Wait for the first resource to become reconciling after operator replacement.
420
+ # This confirms the MCK operator has started reconciling the resources
395
421
ops_manager .om_status ().assert_reaches_phase (Phase .Pending , timeout = 600 )
396
422
397
423
398
424
@pytest .mark .e2e_olm_meko_operator_upgrade_with_resources
399
- def test_resources_in_running_state_after_upgrade (
425
+ def test_resources_in_running_state_after_migration (
400
426
ops_manager : MongoDBOpsManager ,
401
427
oplog_replica_set : MongoDB ,
402
428
blockstore_replica_set : MongoDB ,
@@ -414,7 +440,7 @@ def test_resources_in_running_state_after_upgrade(
414
440
415
441
416
442
@pytest .mark .e2e_olm_meko_operator_upgrade_with_resources
417
- def test_resources_connectivity_after_upgrade (
443
+ def test_resources_connectivity_after_migration (
418
444
ca_path : str ,
419
445
ops_manager : MongoDBOpsManager ,
420
446
oplog_replica_set : MongoDB ,
0 commit comments