From 05ce848a6f5cbd8e703dfcec5ad09dab2988acba Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Fri, 2 Jun 2023 21:29:09 +0300 Subject: [PATCH] Support hubless environment in ramenctl If environment does not have a hub: - `ramenctl deploy` skips hub deployment - `ramenctl undeploy` skips the hub deployment - `ramenctl config` installs the s3 secret and ramen-dr-cluster-operator-config map on the dr clusters. - `ramenctl unconfig` delete the s3 secrets from the dr clusters. Signed-off-by: Nir Soffer --- ramenctl/ramenctl/config.py | 27 ++++++++++++++++++--------- ramenctl/ramenctl/deploy.py | 14 +++++++++----- ramenctl/ramenctl/unconfig.py | 30 ++++++++++++++++++------------ ramenctl/ramenctl/undeploy.py | 7 ++++--- 4 files changed, 49 insertions(+), 29 deletions(-) diff --git a/ramenctl/ramenctl/config.py b/ramenctl/ramenctl/config.py index 68ef8a8ff8..7c5ef4fff0 100644 --- a/ramenctl/ramenctl/config.py +++ b/ramenctl/ramenctl/config.py @@ -23,18 +23,27 @@ def run(args): s3_secret = generate_ramen_s3_secret(args) cloud_secret = generate_cloud_credentials_secret(env["clusters"][0], args) - hub_cm = generate_config_map("hub", env["clusters"], args) - wait_for_ramen_hub_operator(env["hub"], args) + if env["hub"]: + hub_cm = generate_config_map("hub", env["clusters"], args) - create_ramen_s3_secret(env["hub"], s3_secret) - for cluster in env["clusters"]: - create_cloud_credentials_secret(cluster, cloud_secret) - create_ramen_config_map(env["hub"], hub_cm) - create_hub_dr_resources(env["hub"], env["clusters"], env["topology"]) + wait_for_ramen_hub_operator(env["hub"], args) - wait_for_dr_clusters(env["hub"], env["clusters"], args) - wait_for_dr_policy(env["hub"], args) + create_ramen_s3_secret(env["hub"], s3_secret) + for cluster in env["clusters"]: + create_cloud_credentials_secret(cluster, cloud_secret) + create_ramen_config_map(env["hub"], hub_cm) + create_hub_dr_resources(env["hub"], env["clusters"], env["topology"]) + + wait_for_dr_clusters(env["hub"], env["clusters"], args) + wait_for_dr_policy(env["hub"], args) + else: + dr_cluster_cm = generate_config_map("dr-cluster", env["clusters"], args) + + for cluster in env["clusters"]: + create_ramen_s3_secret(cluster, s3_secret) + create_cloud_credentials_secret(cluster, cloud_secret) + create_ramen_config_map(cluster, dr_cluster_cm) def wait_for_ramen_hub_operator(hub, args): diff --git a/ramenctl/ramenctl/deploy.py b/ramenctl/ramenctl/deploy.py index 3b29f60a21..b2f263e783 100644 --- a/ramenctl/ramenctl/deploy.py +++ b/ramenctl/ramenctl/deploy.py @@ -37,13 +37,17 @@ def load_image(cluster): command.info("Loading image in cluster '%s'", cluster) command.watch("minikube", "--profile", cluster, "image", "load", tar) - clusters = [env["hub"]] + env["clusters"] + all_clusters = env["clusters"][:] + if env["hub"]: + all_clusters.append(env["hub"]) + with concurrent.futures.ThreadPoolExecutor() as executor: - list(executor.map(load_image, clusters)) + list(executor.map(load_image, all_clusters)) - command.info("Deploying ramen operator in cluster '%s'", env["hub"]) - command.watch("kubectl", "config", "use-context", env["hub"]) - command.watch("make", "-C", args.source_dir, "deploy-hub") + if env["hub"]: + command.info("Deploying ramen operator in cluster '%s'", env["hub"]) + command.watch("kubectl", "config", "use-context", env["hub"]) + command.watch("make", "-C", args.source_dir, "deploy-hub") for cluster in env["clusters"]: command.info("Deploying ramen operator in cluster '%s'", cluster) diff --git a/ramenctl/ramenctl/unconfig.py b/ramenctl/ramenctl/unconfig.py index 0d3da66158..82c3714cfe 100644 --- a/ramenctl/ramenctl/unconfig.py +++ b/ramenctl/ramenctl/unconfig.py @@ -20,10 +20,15 @@ def register(commands): def run(args): env = command.env_info(args) - delete_hub_dr_resources(env["hub"], env["clusters"], env["topology"]) # Note: We keep the ramen config map since we do not own it. - delete_s3_secret(env["hub"], args) - delete_cloud_credentials(env["clusters"], args) + + if env["hub"]: + delete_hub_dr_resources(env["hub"], env["clusters"], env["topology"]) + delete_s3_secret([env["hub"]], args) + delete_cloud_credentials(env["clusters"], args) + else: + delete_s3_secret(env["clusters"], args) + delete_cloud_credentials(env["clusters"], args) def delete_hub_dr_resources(hub, clusters, topology): @@ -41,17 +46,18 @@ def delete_hub_dr_resources(hub, clusters, topology): ) -def delete_s3_secret(cluster, args): - command.info("Deleting s3 secret in cluster '%s'", cluster) +def delete_s3_secret(clusters, args): template = drenv.template(command.resource("ramen-s3-secret.yaml")) yaml = template.substitute(namespace=args.ramen_namespace) - kubectl.delete( - "--filename=-", - "--ignore-not-found", - input=yaml, - context=cluster, - log=command.debug, - ) + for cluster in clusters: + command.info("Deleting s3 secret in cluster '%s'", cluster) + kubectl.delete( + "--filename=-", + "--ignore-not-found", + input=yaml, + context=cluster, + log=command.debug, + ) def delete_cloud_credentials(clusters, args): diff --git a/ramenctl/ramenctl/undeploy.py b/ramenctl/ramenctl/undeploy.py index 1caeefe440..e1628c42bc 100644 --- a/ramenctl/ramenctl/undeploy.py +++ b/ramenctl/ramenctl/undeploy.py @@ -22,6 +22,7 @@ def run(args): command.watch("kubectl", "config", "use-context", cluster) command.watch("make", "-C", args.source_dir, "undeploy-dr-cluster") - command.info("Undeploying ramen operator in cluster '%s'", env["hub"]) - command.watch("kubectl", "config", "use-context", env["hub"]) - command.watch("make", "-C", args.source_dir, "undeploy-hub") + if env["hub"]: + command.info("Undeploying ramen operator in cluster '%s'", env["hub"]) + command.watch("kubectl", "config", "use-context", env["hub"]) + command.watch("make", "-C", args.source_dir, "undeploy-hub")