Skip to content

Commit d08b50e

Browse files
mce rework
Signed-off-by: Daniel Osypenko <[email protected]>
1 parent a5ca728 commit d08b50e

File tree

8 files changed

+111
-105
lines changed

8 files changed

+111
-105
lines changed

ocs_ci/deployment/deployment.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -462,15 +462,8 @@ def do_deploy_mce(self):
462462
463463
"""
464464
if config.DEPLOYMENT.get("deploy_mce"):
465-
if config.ENV_DATA.get("skip_mce_check_if_present"):
466-
check_mce_deployed = False
467-
check_mce_ready = False
468-
else:
469-
check_mce_deployed = True
470-
check_mce_ready = True
471465
mce_installer = MCEInstaller()
472-
mce_installer.deploy_mce(check_mce_deployed, check_mce_ready)
473-
mce_installer.validate_mce_deployment()
466+
mce_installer.deploy_mce()
474467

475468
def do_deploy_oadp(self):
476469
"""

ocs_ci/deployment/hosted_cluster.py

-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ def deploy_dependencies(
534534
self.update_hcp_binary()
535535
if deploy_mce and not deploy_acm_hub:
536536
self.deploy_mce()
537-
self.validate_mce_deployment()
538537

539538
# Enable central infrastructure management service for agent
540539
if config.DEPLOYMENT.get("hosted_cluster_platform") == "agent":

ocs_ci/deployment/mce.py

+101-86
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
import logging
66
import tempfile
77

8-
from ocs_ci.framework import config
9-
from ocs_ci.ocs.resources.ocs import OCS
8+
from ocs_ci.deployment.qe_app_registry import QeAppRegistry
9+
from ocs_ci.ocs import ocp
1010
from ocs_ci.ocs.ocp import OCP
11+
from ocs_ci.ocs.resources.ocs import OCS
12+
from ocs_ci.framework import config
1113
from ocs_ci.utility import templating
1214
from ocs_ci.ocs import constants
1315
from ocs_ci.utility.utils import (
1416
run_cmd,
1517
exec_cmd,
1618
)
1719
from ocs_ci.ocs.resources.catalog_source import CatalogSource
18-
from ocs_ci.ocs import ocp
20+
from ocs_ci.ocs.resources.deployment import Deployment
1921
from ocs_ci.utility.utils import get_running_ocp_version
2022
from ocs_ci.ocs.exceptions import CommandFailed, UnavailableResourceException
2123

@@ -28,22 +30,30 @@ class MCEInstaller(object):
2830
"""
2931

3032
def __init__(self):
31-
self.namespace = constants.MCE_NAMESPACE
33+
self.mce_namespace = constants.MCE_NAMESPACE
3234
self.ns_obj = ocp.OCP(kind=constants.NAMESPACES)
3335
self.hypershift_override_image_cm = "hypershift-override-images-new"
3436
self.multicluster_engine = ocp.OCP(
3537
kind="MultiClusterEngine",
3638
resource_name=constants.MULTICLUSTER_ENGINE,
39+
namespace=self.mce_namespace,
3740
)
3841
self.catsrc = ocp.OCP(
3942
kind=constants.CATSRC, namespace=constants.MARKETPLACE_NAMESPACE
4043
)
4144
self.subs = ocp.OCP(kind=constants.PROVIDER_SUBSCRIPTION)
4245

43-
def create_mce_catalog_source(self):
46+
def _create_mce_catalog_source(self):
4447
"""
4548
Creates a catalogsource for mce operator.
4649
50+
We use qe-app-registry catalog source to install latest version
51+
In future if we want to install particular image we can use subscription.spec.startingCSV:<image> like
52+
quay.io:443/acm-d/mce-custom-registry:2.13.0-DOWNSTREAM-2025-03-02-02-49-35
53+
In this case we don't need another channel in subscription but may reuse stable-2.8 channel
54+
55+
! Important. This catalog source does not work without ICSP, this catsrc is not used in a moment.
56+
! This method was left for reference only.
4757
"""
4858
if not self.catsrc.is_exist(
4959
resource_name=constants.MCE_CATSRC_NAME,
@@ -79,15 +89,13 @@ def create_mce_namespace(self):
7989
CommandFailed: If the 'oc create' command fails.
8090
"""
8191
if not self.ns_obj.is_exist(
82-
resource_name=self.namespace,
92+
resource_name=self.mce_namespace,
8393
):
84-
logger.info(f"Creating namespace {self.namespace} for mce resources")
94+
logger.info(f"Creating namespace {self.mce_namespace} for mce resources")
8595
namespace_yaml_file = templating.load_yaml(constants.MCE_NAMESPACE_YAML)
8696
namespace_yaml = OCS(**namespace_yaml_file)
8797
namespace_yaml.create()
88-
logger.info(f"MCE namespace {self.namespace} was created successfully")
89-
else:
90-
logger.info(f"{self.namespace} already exists")
98+
logger.info(f"MCE namespace {self.mce_namespace} was created successfully")
9199

92100
def create_multiclusterengine_operatorgroup(self):
93101
"""
@@ -98,14 +106,12 @@ def create_multiclusterengine_operatorgroup(self):
98106
if not self.multicluster_engine.is_exist(
99107
resource_name=constants.MULTICLUSTER_ENGINE
100108
):
101-
102109
operatorgroup_yaml_file = templating.load_yaml(
103110
constants.MCE_OPERATOR_GROUP_YAML
104111
)
105112
operatorgroup_yaml = OCS(**operatorgroup_yaml_file)
106113
operatorgroup_yaml.create()
107114
logger.info("mce OperatorGroup created successfully")
108-
self.multicluster_engine.wait_for_phase("Available")
109115

110116
def create_multiclusterengine_resource(self):
111117
"""
@@ -128,26 +134,23 @@ def create_mce_subscription(self):
128134
constants.MCE_SUBSCRIPTION_YAML
129135
)
130136

131-
if config.DEPLOYMENT.get("mce_latest_stable"):
132-
mce_subscription_yaml_data["spec"][
133-
"source"
134-
] = constants.OPERATOR_CATALOG_SOURCE_NAME
135-
mce_channel = "stable"
136-
else:
137-
mce_channel = config.DEPLOYMENT.get("mce_channel")
137+
# ! Important, channel-2.8 becomes available after OCP 4.18 release
138+
if config.DEPLOYMENT.get("mce_channel"):
139+
mce_subscription_yaml_data["spec"]["channel"] = config.DEPLOYMENT.get(
140+
"mce_channel"
141+
)
138142

139-
mce_subscription_yaml_data["spec"]["channel"] = mce_channel
140143
mce_subscription_manifest = tempfile.NamedTemporaryFile(
141144
mode="w+", prefix="mce_subscription_manifest", delete=False
142145
)
143146
templating.dump_data_to_temp_yaml(
144147
mce_subscription_yaml_data, mce_subscription_manifest.name
145148
)
146-
logger.info("Creating subscription for mce operator")
147-
run_cmd(f"oc create -f {mce_subscription_manifest.name}")
149+
logger.info("Creating subscription for the mce operator")
150+
exec_cmd(f"oc create -f {mce_subscription_manifest.name}")
148151
OCP(
149152
kind=constants.SUBSCRIPTION_COREOS,
150-
namespace=self.namespace,
153+
namespace=self.mce_namespace,
151154
resource_name=constants.MCE_OPERATOR,
152155
).check_resource_existence(
153156
should_exist=True, resource_name=constants.MCE_OPERATOR
@@ -160,7 +163,9 @@ def check_hypershift_namespace(self):
160163
Check hypershift namespace created
161164
162165
"""
163-
logger.info(f"hypershift namespace {self.namespace} was created successfully")
166+
logger.info(
167+
f"hypershift namespace {self.mce_namespace} was created successfully"
168+
)
164169
is_hypershift_ns_available = self.ns_obj.is_exist(
165170
resource_name=constants.HYPERSHIFT_NAMESPACE,
166171
)
@@ -176,15 +181,20 @@ def check_supported_versions(self):
176181
namespace=constants.HYPERSHIFT_NAMESPACE,
177182
)
178183

179-
if not configmaps_obj.is_exist(
180-
resource_name=constants.SUPPORTED_VERSIONS_CONFIGMAP
184+
if not configmaps_obj.check_resource_existence(
185+
should_exist=True,
186+
timeout=60,
187+
resource_name=constants.SUPPORTED_VERSIONS_CONFIGMAP,
181188
):
182189
raise UnavailableResourceException(
183-
f"Configmap {constants.SUPPORTED_VERSIONS_CONFIGMAP} does not exist in hypershift namespace"
190+
f"Configmap {constants.SUPPORTED_VERSIONS_CONFIGMAP} does not exist "
191+
f"in {constants.HYPERSHIFT_NAMESPACE} namespace"
184192
)
185193

186-
cmd = "oc get cm -n hypershift supported-versions -o jsonpath='{.data.supported-versions}'"
194+
cmd = f"oc get cm -n {constants.HYPERSHIFT_NAMESPACE} supported-versions "
195+
cmd += "-o jsonpath='{.data.supported-versions}'"
187196
cmd_res = exec_cmd(cmd, shell=True)
197+
supported_versions = ""
188198
if cmd_res.returncode == 0:
189199
supported_versions = cmd_res.stdout.decode("utf-8")
190200
logger.info(f"Supported versions: {supported_versions}")
@@ -199,7 +209,7 @@ def create_image_override(self):
199209
# Create image override configmap using the image override json
200210
cmd = (
201211
f"oc create cm {self.hypershift_override_image_cm} --from-file={constants.IMAGE_OVERRIDE_JSON}"
202-
"-n {self.namespace}"
212+
f"-n {self.mce_namespace}"
203213
)
204214
cmd_res = exec_cmd(cmd, shell=True)
205215
if cmd_res.returncode:
@@ -211,43 +221,36 @@ def create_image_override(self):
211221
)
212222
self.multicluster_engine.wait_until_running()
213223

214-
def deploy_mce(self, check_mce_deployed=False, check_mce_ready=False):
224+
def deploy_mce(self):
215225
"""
216226
Installs mce enabling software emulation.
217227
218-
Args:
219-
check_mce_deployed (bool): If True, check if mce is already deployed. If so, skip the deployment.
220-
check_mce_ready (bool): If True, check if mce is ready. If so, skip the deployment.
221228
"""
222-
if check_mce_deployed:
223-
if self.mce_installed():
224-
logger.info("mce operator is already deployed, skipping the deployment")
225-
return
226-
227-
if check_mce_ready:
228-
if self.post_install_verification(raise_exception=False):
229-
logger.info("mce operator ready, skipping the deployment")
230-
return
231-
232-
logger.info("Installing mce")
233-
# we create catsrc with nightly builds only if config.DEPLOYMENT does not have mce_latest_stable
234-
if not config.DEPLOYMENT.get("mce_latest_stable"):
235-
# Create mce catalog source
236-
self.create_mce_catalog_source()
237-
# Create multicluster-engine namespace
238-
self.create_mce_namespace()
239-
# create mce subscription
240-
self.create_mce_subscription()
241-
# Deploy the multiclusterengine operatorgroup
242-
self.create_multiclusterengine_operatorgroup()
243-
# Create mce resource
244-
self.create_multiclusterengine_resource()
245-
# Check hypershift ns created
246-
if not self.check_hypershift_namespace():
247-
cmd = f"oc create namespace {constants.HYPERSHIFT_NAMESPACE}"
248-
cmd_res = exec_cmd(cmd, shell=True)
249-
if cmd_res.returncode:
250-
raise CommandFailed("Failed to create hypershift namespace")
229+
230+
if not self.mce_installed():
231+
logger.info("Installing mce")
232+
# we create catsrc with nightly builds only if config.DEPLOYMENT does not have mce_latest_stable
233+
qe_app_registry = QeAppRegistry()
234+
qe_app_registry.icsp()
235+
qe_app_registry.catalog_source()
236+
self.create_mce_namespace()
237+
self.create_mce_subscription()
238+
self.create_multiclusterengine_operatorgroup()
239+
240+
# check whether mce instance is created, if it is installed but mce don't pass validation we can not heal it in
241+
# script here, hence no sense for full validation of mce
242+
if not self.mce_exists():
243+
244+
# Create mce resource
245+
self.create_multiclusterengine_resource()
246+
# Check hypershift ns created
247+
if not self.check_hypershift_namespace():
248+
cmd = f"oc create namespace {constants.HYPERSHIFT_NAMESPACE}"
249+
cmd_res = exec_cmd(cmd, shell=True)
250+
if cmd_res.returncode:
251+
raise CommandFailed("Failed to create hypershift namespace")
252+
253+
self.wait_mce_resources()
251254
# Check supported versions in supported-versions configmap
252255
self.check_supported_versions()
253256

@@ -258,36 +261,48 @@ def mce_installed(self):
258261
Returns:
259262
bool: True if MCE is installed, False otherwise
260263
"""
261-
ocp = OCP(kind=constants.ROOK_OPERATOR, namespace=self.namespace)
262-
return ocp.check_resource_existence(
263-
timeout=12, should_exist=True, resource_name=constants.MCE_OPERATOR
264+
ocp_obj = OCP(kind=constants.ROOK_OPERATOR)
265+
# unlike other k8s resources, operators are OLM manager resources that identified by merged name.namespace
266+
return ocp_obj.check_resource_existence(
267+
timeout=12,
268+
should_exist=True,
269+
resource_name=constants.MCE_OPERATOR_OPERATOR_NAME_WITH_NS,
264270
)
265271

266-
def post_install_verification(self, raise_exception=False):
272+
def mce_exists(self):
267273
"""
268-
Performs MCE post-installation verification, with raise_exception = False may be used safely to run on
269-
clusters with MCE installed or not installed.
270-
271-
Args:
272-
raise_exception: If True, allow function to fail the job and raise an exception. If false, return False
273-
instead of raising an exception.
274+
Check if MCE exists
274275
275276
Returns:
276-
bool: True if the verification conditions are met, False otherwise
277-
Raises:
278-
TimeoutExpiredError: If the verification conditions are not met within the timeout
279-
and raise_exception is True.
280-
ResourceNotFoundError if the namespace does not exist and raise_exception is True.
281-
ResourceWrongStatusException if the nodes are not ready, verification fails and raise_exception
282-
is True.
277+
bool: True if MCE exists, False otherwise
283278
"""
284-
# TODO: implement
285-
pass
279+
return self.multicluster_engine.is_exist(
280+
resource_name=constants.MULTICLUSTER_ENGINE
281+
)
286282

287-
def validate_mce_deployment(self):
283+
def wait_mce_resources(self):
288284
"""
289-
Validate mce operator installation
285+
Wait for mce Available state and deployments Ready state
286+
287+
Raises:
288+
TimeoutExpiredError: If the deployment is not in the 'Available' state within the timeout
290289
"""
291-
if self.mce_hyperconverged_installed():
292-
logger.info("mce operator is already deployed")
293-
return
290+
if not self.mce_exists():
291+
raise UnavailableResourceException("MCE resource is not created")
292+
deployments = [
293+
"multicluster-engine-operator",
294+
"ocm-controller",
295+
"cluster-manager",
296+
"ocm-webhook",
297+
]
298+
299+
for resource_name in deployments:
300+
depl_ocp_obj = OCP(
301+
kind=constants.DEPLOYMENT,
302+
namespace=self.mce_namespace,
303+
resource_name=resource_name,
304+
)
305+
deployment_obj = Deployment(
306+
**depl_ocp_obj.get(retry=60, wait=10, dont_raise=True)
307+
)
308+
deployment_obj.wait_for_available_replicas(timeout=600)

ocs_ci/framework/conf/default_config.yaml

+4-5
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ DEPLOYMENT:
123123
rosa_cli_version: '1.2.49'
124124
# Multicluster engine
125125
deploy_mce: false
126+
# ! Pay attention. stable-2.8 is not available until OCP 4.18 becomes available
127+
mce_channel: "stable-2.8"
128+
# catalogsource format of image with tag; latest unreleased, that is supported by OCP 4.18
129+
mce_image: ""
126130

127131

128132

@@ -232,9 +236,6 @@ ENV_DATA:
232236
rhel7.9_worker_ami: 'ami-058a93d58c5797698'
233237
rhel8.4_worker_ami: 'ami-074bab065c112399f'
234238
cluster_type: ""
235-
# Provider mode dependencies checks during deployment for presence
236-
skip_mce_check_if_present: false
237-
skip_cnv_check_if_present: false
238239

239240
# RHEL template which are used for vSphere platform
240241
rhel7_template: 'rhel79_ocs4qe'
@@ -243,8 +244,6 @@ ENV_DATA:
243244
deploy_acm_hub_cluster: false
244245
# HyperConverged deployment
245246
deploy_hyperconverged: false
246-
# mce deployment
247-
deploy_mce: false
248247

249248
# Managed service git stat default configurations
250249
# Managed StorageCluster size in TiB

ocs_ci/ocs/constants.py

+1
Original file line numberDiff line numberDiff line change
@@ -2806,6 +2806,7 @@
28062806
TEMPLATE_DEPLOYMENT_DIR_MCE, "mce_subscription.yaml"
28072807
)
28082808
MCE_OPERATOR = "multicluster-engine"
2809+
MCE_OPERATOR_OPERATOR_NAME_WITH_NS = f"{MCE_OPERATOR}.{MCE_NAMESPACE}"
28092810
MCE_RESOURCE_YAML = os.path.join(TEMPLATE_DEPLOYMENT_DIR_MCE, "mce_resource.yaml")
28102811
MCE_OPERATOR_GROUP_YAML = os.path.join(
28112812
TEMPLATE_DEPLOYMENT_DIR_MCE, "mce_operatorgroup.yaml"

ocs_ci/templates/mce-deployment/mce_catsrc.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ metadata:
44
name: mce-catalogsource
55
namespace: openshift-marketplace
66
spec:
7-
image: quay.io:443/acm-d/mce-custom-registry:2.13.0-DOWNSTREAM-2025-02-25-05-34-41
7+
# latest version of the catalog image for OCP 4.18
8+
image: quay.io:443/acm-d/mce-custom-registry:2.8-latest
89
sourceType: grpc

ocs_ci/templates/mce-deployment/mce_subscription.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ metadata:
44
name: multicluster-engine
55
namespace: multicluster-engine
66
spec:
7-
channel: stable
7+
channel: stable-2.8
88
installPlanApproval: Automatic
99
name: multicluster-engine
10-
source: mce-catalogsource
10+
source: qe-app-registry
1111
sourceNamespace: openshift-marketplace

0 commit comments

Comments
 (0)