Skip to content

Commit

Permalink
code fixes and feedback
Browse files Browse the repository at this point in the history
Signed-off-by: am-agrawa <amagrawa@redhat.com>
  • Loading branch information
am-agrawa committed May 17, 2024
1 parent 867e790 commit 1c694b1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 24 deletions.
80 changes: 57 additions & 23 deletions ocs_ci/deployment/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand All @@ -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):
"""
Expand All @@ -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
)
Expand All @@ -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'"
Expand Down
2 changes: 1 addition & 1 deletion ocs_ci/templates/DR/multiclusterobservability.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ spec:
name: thanos-object-storage
receiveStorageSize: 100Gi
ruleStorageSize: 1Gi
storageClass: thin-csi-odf
storageClass: PLACEHOLDER
storeStorageSize: 10Gi

0 comments on commit 1c694b1

Please sign in to comment.