-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement OCP DR clusters deployment using ACM UI Signed-off-by: Shylesh Kumar Mohan <[email protected]>
- Loading branch information
Showing
10 changed files
with
783 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ENV_DATA: | ||
acm_ocp_deployment: True | ||
UI_SELENIUM: | ||
headless: False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
MULTICLUSTER: | ||
# Other modes could be managed services | ||
multicluster_mode: "regional-dr" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import logging | ||
|
||
from ocs_ci.deployment.deployment import Deployment | ||
from ocs_ci.framework import config | ||
from ocs_ci.ocs.exceptions import ACMClusterDeployException | ||
from ocs_ci.ocs.ui import acm_ui | ||
from ocs_ci.ocs.utils import get_non_acm_cluster_config | ||
from ocs_ci.ocs.acm import acm | ||
from ocs_ci.ocs import constants | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class OCPDeployWithACM(Deployment): | ||
""" | ||
When we instantiate this class, the assumption is we already have | ||
an OCP cluster with ACM installed and current context is ACM | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
When we init Deployment class it will have all the | ||
ACM cluster's context | ||
""" | ||
super().__init__() | ||
self.multicluster_mode = config.MULTICLUSTER.get("multicluster_mode", None) | ||
# Used for housekeeping during multiple OCP cluster deployments | ||
self.deployment_cluster_list = list() | ||
# Whether to start deployment in asynchronous mode or synchronous mode | ||
# In async deploy mode, we will have a single wait method waiting for | ||
# all the cluster deployments to finish | ||
self.deploy_sync_mode = config.MULTICLUSTER.get("deploy_sync_mode", "async") | ||
self.ui_driver = None | ||
|
||
def do_deploy_ocp(self, log_cli_level="INFO"): | ||
""" | ||
This function overrides the parent's function in order accomodate | ||
ACM based OCP cluster deployments | ||
""" | ||
if self.multicluster_mode == constants.RDR_MODE: | ||
self.do_rdr_acm_ocp_deploy() | ||
|
||
def do_rdr_acm_ocp_deploy(self): | ||
""" | ||
Specific to regional DR OCP cluster deployments | ||
""" | ||
factory = acm_ui.ACMOCPDeploymentFactory() | ||
self.ui_driver = acm.login_to_acm() | ||
|
||
if self.deploy_sync_mode == "async": | ||
rdr_clusters = get_non_acm_cluster_config() | ||
for c in rdr_clusters: | ||
logger.info(f"{c.ENV_DATA['cluster_name']}") | ||
logger.info(f"{c.ENV_DATA['platform']}") | ||
logger.info(f"{c.ENV_DATA['deployment_type']}") | ||
for cluster_conf in rdr_clusters: | ||
deployer = factory.get_platform_instance(self.ui_driver, cluster_conf) | ||
deployer.create_cluster_prereq() | ||
deployer.create_cluster() | ||
self.deployment_cluster_list.append(deployer) | ||
# At this point deployment of all non-acm ocp clusters have been | ||
# triggered, we need to wait for all of them to succeed | ||
self.wait_for_all_clusters_async() | ||
# Download kubeconfig to the respective directories | ||
for cluster in self.deployment_cluster_list: | ||
cluster.download_cluster_conf_files() | ||
|
||
def wait_for_all_clusters_async(self): | ||
# We will say done only when none of the clusters are in | ||
# 'Creating' state. Either they have to be in 'Ready' state | ||
# OR 'Failed' state | ||
done_waiting = False | ||
while not done_waiting: | ||
done_waiting = True | ||
for cluster in self.deployment_cluster_list: | ||
if cluster.deployment_status not in ["ready", "failed"]: | ||
cluster.get_deployment_status() | ||
done_waiting = False | ||
# We will fail even if one of the clusters failed to deploy | ||
failed_list = list() | ||
success_list = list() | ||
for cluster in self.deployment_cluster_list: | ||
if cluster.deployment_status == "failed": | ||
failed_list.append(cluster) | ||
else: | ||
success_list.append(cluster) | ||
|
||
if success_list: | ||
logger.info("Deployment for following clusters Passed") | ||
logger.info(f"{[c.cluster_name for c in success_list]}") | ||
if failed_list: | ||
logger.error("Deployment failed for following clusters") | ||
logger.error(f"{[c.cluster_name for c in failed_list]}") | ||
raise ACMClusterDeployException("one or more Cluster Deployment failed ") | ||
|
||
def deploy_cluster(self, log_cli_level="INFO"): | ||
""" | ||
We deploy new OCP clusters using ACM | ||
Note: Importing cluster through ACM has been implemented as part | ||
of Jenkins pipeline | ||
""" | ||
|
||
super().deploy_cluster(log_cli_level=log_cli_level) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.