Skip to content

Commit

Permalink
code base to enable ACM observability
Browse files Browse the repository at this point in the history
Signed-off-by: am-agrawa <[email protected]>
  • Loading branch information
am-agrawa committed Apr 6, 2024
1 parent bde688e commit 9438f5a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 28 deletions.
80 changes: 80 additions & 0 deletions ocs_ci/deployment/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
CephClusterExternal,
get_lvm_full_version,
)
from ocs_ci.ocs.constants import (
MULTICLUSTEROBSERVABILITY_PATH,
OBSERVABILITYMETRICSCONFIGMAP_PATH,
THANOS_PATH,
)
from ocs_ci.ocs.exceptions import (
CephHealthException,
ChannelNotFound,
Expand All @@ -52,6 +57,7 @@
UnsupportedFeatureError,
UnexpectedDeploymentConfiguration,
MDRDeploymentException,
ACMObservabilityNotEnabled,
)
from ocs_ci.deployment.cert_manager import deploy_cert_manager
from ocs_ci.deployment.zones import create_dummy_zone_labels
Expand Down Expand Up @@ -2877,6 +2883,80 @@ def deploy(self):
rbddops.deploy()
self.deploy_dr_policy()

def build_bucket_name(self, acm_indexes: list):
"""
Create a bucket to be used in the thanos.yaml for ACM observability
Args:
acm_indexes (list): List of acm indexes
"""
self.bucket_name = ""
for index in acm_indexes:
self.bucket_name += config.clusters[index].ENV_DATA["cluster_name"]
return self.bucket_name

@retry(ACMObservabilityNotEnabled, tries=10, delay=5, backoff=5)
def thanos_secret(self):
"""
Create thanos secret yaml by using Noobaa or AWS bucket (AWS bucket is used in this function)
"""
secret_dict = load_auth_config().get("AUTH", {})
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"][
"bucket"
] = self.build_bucket_name()
thanos_secret_data["stringData"]["thanos.yaml"][
"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_data_yaml = tempfile.NamedTemporaryFile(
mode="w+", prefix="thanos", delete=False
)
templating.dump_data_to_temp_yaml(thanos_secret_data, thanos_data_yaml.name)

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)

check_observability_status = run_cmd(
"oc get MultiClusterObservability observability -o jsonpath='{.status.conditions[1].status}'"
)
if check_observability_status:
logger.info("ACM observability is successfully enabled")
else:
raise ACMObservabilityNotEnabled(
"ACM Observability is not enabled, status is False"
)

def enable_acm_observability(self):
"""
Function to enable ACM observability for enabling DR monitoring dashboard for Regional DR on the RHACM console.
"""

logger.info("Enable ACM MultiClusterObservability")
run_cmd(f"oc create -f {MULTICLUSTEROBSERVABILITY_PATH}")

logger.info("Whitelist RBD metrics and create configmap")
run_cmd(f"oc create -f {OBSERVABILITYMETRICSCONFIGMAP_PATH}")

logger.info("Enable thanos secret yaml")
self.thanos_secret()

logger.info(
"Add label for cluster-monitoring needed to fire VolumeSyncronizationDelayAlert"
)
run_cmd(
"oc label namespace openshift-operators openshift.io/cluster-monitoring='true'"
)


class MDRMultiClusterDROperatorsDeploy(MultiClusterDROperatorsDeploy):
"""
Expand Down
29 changes: 1 addition & 28 deletions ocs_ci/helpers/dr_helpers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
Helper functions specific for DR
"""

import json
import logging
import tempfile
import boto3

from ocs_ci.framework import config
from ocs_ci.ocs import constants, ocp
Expand All @@ -23,7 +23,6 @@
from ocs_ci.utility import version, templating
from ocs_ci.utility.retry import retry
from ocs_ci.utility.utils import TimeoutSampler, CommandFailed, run_cmd
from botocore.exceptions import BotoCoreError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1085,29 +1084,3 @@ def verify_drpolicy_cli(switch_ctx=None):
raise UnexpectedBehaviour(
f"DRPolicy is not in succeeded or validated state: {status}"
)


def create_s3_bucket(access_key, secret_key, bucket_name):
"""
Create s3 bucket
Args:
access_key (str): S3 access key
secret_key (str): S3 secret key
acm_indexes (list): List of acm indexes
"""
client = boto3.resource(
"s3",
verify=True,
endpoint_url="https://s3.amazonaws.com",
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
)
try:
client.create_bucket(
Bucket=bucket_name,
CreateBucketConfiguration={"LocationConstraint": constants.AWS_REGION},
)
logger.info(f"Successfully created backup bucket: {bucket_name}")
except BotoCoreError as e:
logger.error(f"Failed to create s3 bucket {e}")
raise
7 changes: 7 additions & 0 deletions ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2421,6 +2421,13 @@

# DR
DRPC_PATH = os.path.join(TEMPLATE_DIR, "DR", "drpc.yaml")
MULTICLUSTEROBSERVABILITY_PATH = os.path.join(
TEMPLATE_DIR, "DR", "multiclusterobservability.yaml"
)
OBSERVABILITYMETRICSCONFIGMAP_PATH = os.path.join(
TEMPLATE_DIR, "DR", "observability-metrics-configmap.yaml"
)
THANOS_PATH = os.path.join(TEMPLATE_DIR, "DR", "thanos.yaml")
APPLICATION_SET = "ApplicationSet"
PLACEMENT = "Placement"
GITOPS_CLUSTER_NAMESPACE = "openshift-gitops"
Expand Down
4 changes: 4 additions & 0 deletions ocs_ci/ocs/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,3 +690,7 @@ class NoRunningCephToolBoxException(Exception):

class UsernameNotFoundException(Exception):
pass


class ACMObservabilityNotEnabled(Exception):
pass

0 comments on commit 9438f5a

Please sign in to comment.