From 1c694b1c3c6a82f487584e59a5196f57b9225c54 Mon Sep 17 00:00:00 2001 From: am-agrawa Date: Fri, 17 May 2024 16:16:15 +0530 Subject: [PATCH] code fixes and feedback Signed-off-by: am-agrawa --- ocs_ci/deployment/deployment.py | 80 +++++++++++++------ .../DR/multiclusterobservability.yaml | 2 +- 2 files changed, 58 insertions(+), 24 deletions(-) diff --git a/ocs_ci/deployment/deployment.py b/ocs_ci/deployment/deployment.py index 5e8aa8376748..5241e94a153d 100644 --- a/ocs_ci/deployment/deployment.py +++ b/ocs_ci/deployment/deployment.py @@ -41,9 +41,7 @@ check_cephcluster_status, ) from ocs_ci.ocs.constants import ( - MULTICLUSTEROBSERVABILITY_PATH, OBSERVABILITYMETRICSCONFIGMAP_PATH, - THANOS_PATH, ) from ocs_ci.ocs.exceptions import ( CephHealthException, @@ -148,6 +146,7 @@ from ocs_ci.helpers import helpers from ocs_ci.helpers.helpers import ( set_configmap_log_level_rook_ceph_operator, + get_default_storage_class, ) from ocs_ci.ocs.ui.helpers_ui import ui_deployment_conditions from ocs_ci.utility.utils import get_az_count @@ -447,6 +446,7 @@ def do_deploy_rdr(self): dr_conf = self.get_rdr_conf() deploy_dr = get_multicluster_dr_deployment()(dr_conf) deploy_dr.deploy() + deploy_dr.enable def do_deploy_lvmo(self): """ @@ -2934,6 +2934,10 @@ def __init__(self, dr_conf): self.rbd = dr_conf.get("rbd_dr_scenario", False) # CephFS For future usecase self.cephfs = dr_conf.get("cephfs_dr_scenario", False) + self.thanos_yaml_file = os.path.join(constants.THANOS_PATH) + self.multiclusterobservability_file = os.path.join( + constants.MULTICLUSTEROBSERVABILITY_PATH + ) def deploy(self): """ @@ -2948,6 +2952,7 @@ def deploy(self): self.configure_mirror_peer() rbddops.deploy() self.deploy_dr_policy() + self.enable_acm_observability() def build_bucket_name(self, acm_indexes: list): """ @@ -2960,6 +2965,18 @@ def build_bucket_name(self, acm_indexes: list): self.bucket_name += config.clusters[index].ENV_DATA["cluster_name"] return self.bucket_name + retry(CommandFailed, tries=10, delay=30) + + def check_observability_status(self): + """ + Check observability status + Returns (bool): True or False + + """ + return run_cmd( + "oc get MultiClusterObservability observability -o jsonpath='{.status.conditions[1].status}'" + ) + @retry(ACMObservabilityNotEnabled, tries=10, delay=5, backoff=5) def thanos_secret(self): """ @@ -2970,14 +2987,18 @@ def thanos_secret(self): access_key = secret_dict["AWS"]["AWS_ACCESS_KEY_ID"] secret_key = secret_dict["AWS"]["AWS_SECRET_ACCESS_KEY"] thanos_secret_data = templating.load_yaml(self.thanos_yaml_file) - thanos_secret_data["stringData"]["thanos.yaml"][ + thanos_secret_data["stringData"]["thanos.yaml"]["config"][ "bucket" ] = self.build_bucket_name() - thanos_secret_data["stringData"]["thanos.yaml"][ + thanos_secret_data["stringData"]["thanos.yaml"]["config"][ "endpoint" ] = "https://s3.amazonaws.com" - thanos_secret_data["stringData"]["thanos.yaml"]["access_key"] = access_key - thanos_secret_data["stringData"]["thanos.yaml"]["secret_key"] = secret_key + thanos_secret_data["stringData"]["thanos.yaml"]["config"][ + "access_key" + ] = access_key + thanos_secret_data["stringData"]["thanos.yaml"]["config"][ + "secret_key" + ] = secret_key thanos_data_yaml = tempfile.NamedTemporaryFile( mode="w+", prefix="thanos", delete=False ) @@ -2986,38 +3007,51 @@ def thanos_secret(self): logger.info( "Creating thanos.yaml needed for ACM observability after passing required params" ) - run_cmd(f"oc create -f {THANOS_PATH}") - - logger.info("Allow some time for ACM Observability to be enabled") - time.sleep(120) + run_cmd(f"oc create -f {thanos_data_yaml.name}") - check_observability_status = run_cmd( - "oc get MultiClusterObservability observability -o jsonpath='{.status.conditions[1].status}'" - ) - if check_observability_status: + if self.check_observability_status(): logger.info("ACM observability is successfully enabled") else: - raise ACMObservabilityNotEnabled( - "ACM Observability is not enabled, status is False" - ) + logger.error("ACM observability is not enabled") def enable_acm_observability(self): """ Function to enable ACM observability for enabling DR monitoring dashboard for Regional DR on the RHACM console. """ + config.switch_acm_ctx() - logger.info("Enable ACM MultiClusterObservability") - run_cmd(f"oc create -f {MULTICLUSTEROBSERVABILITY_PATH}") + defaultstorageclass = get_default_storage_class() - logger.info("Whitelist RBD metrics and create configmap") - run_cmd(f"oc create -f {OBSERVABILITYMETRICSCONFIGMAP_PATH}") + logger.info( + "Enabling ACM MultiClusterObservability for DR monitoring dashboard" + ) + + # load multiclusterobservability.yaml + multiclusterobservability_yaml_data = templating.load_yaml( + self.multiclusterobservability_file + ) + multiclusterobservability_yaml_data["spec"]["storageConfig"][ + "storageClass" + ] = defaultstorageclass[0] + multiclusterobservability_data_yaml = tempfile.NamedTemporaryFile( + mode="w+", prefix="multiclusterobservability", delete=False + ) + templating.dump_data_to_temp_yaml( + multiclusterobservability_yaml_data, + multiclusterobservability_data_yaml.name, + ) - logger.info("Enable thanos secret yaml") + run_cmd(f"oc create -f {multiclusterobservability_data_yaml.name}") + + logger.info("Create thanos secret yaml") self.thanos_secret() + logger.info("Whitelist RBD metrics by creating configmap") + run_cmd(f"oc create -f {OBSERVABILITYMETRICSCONFIGMAP_PATH}") + logger.info( - "Add label for cluster-monitoring needed to fire VolumeSyncronizationDelayAlert" + "Add label for cluster-monitoring needed to fire VolumeSyncronizationDelayAlert on the Hub cluster" ) run_cmd( "oc label namespace openshift-operators openshift.io/cluster-monitoring='true'" diff --git a/ocs_ci/templates/DR/multiclusterobservability.yaml b/ocs_ci/templates/DR/multiclusterobservability.yaml index 9a9bb269e615..5537d28601ed 100644 --- a/ocs_ci/templates/DR/multiclusterobservability.yaml +++ b/ocs_ci/templates/DR/multiclusterobservability.yaml @@ -18,5 +18,5 @@ spec: name: thanos-object-storage receiveStorageSize: 100Gi ruleStorageSize: 1Gi - storageClass: thin-csi-odf + storageClass: PLACEHOLDER storeStorageSize: 10Gi