diff --git a/ramenctl/ramenctl/config.py b/ramenctl/ramenctl/config.py index 8b4553c56f..71a2a90ae4 100644 --- a/ramenctl/ramenctl/config.py +++ b/ramenctl/ramenctl/config.py @@ -21,54 +21,77 @@ def register(commands): def run(args): env = command.env_info(args) + if env["hub"]: + wait_for_ramen_hub_operator(env["hub"], args) + apply_s3_secret(env["hub"]) + yaml = generate_config_map("ramen-hub-operator-config", env["clusters"]) + apply_ramen_config_map(env["hub"], yaml) + apply_dr_resources(env["hub"], env["topology"]) + wait_for_dr_clusters(env["hub"], env["clusters"], args) + wait_for_dr_policy(env["hub"], args) + else: + yaml = generate_config_map("ramen-dr-cluster-operator-config", env["clusters"]) + for cluster in env["clusters"]: + apply_s3_secret(cluster) + apply_ramen_config_map(cluster, yaml) + + +def wait_for_ramen_hub_operator(hub, args): command.info("Waiting until ramen-hub-operator is rolled out") kubectl.rollout( "status", "deploy/ramen-hub-operator", f"--namespace={args.ramen_namespace}", "--timeout=180s", - context=env["hub"], + context=hub, log=command.debug, ) - command.info("Creating s3 secret in ramen hub namespace") + +def apply_s3_secret(cluster): + command.info("Creating s3 secret in cluster '%s'", cluster) kubectl.apply( "--filename", command.resource("ramen-s3-secret.yaml"), - context=env["hub"], + context=cluster, log=command.debug, ) - command.info("Updating ramen config map") + +def generate_config_map(name, clusters): template = drenv.template(command.resource("configmap.yaml")) - yaml = template.substitute( + return template.substitute( + name=name, auto_deploy="true", - minio_url_dr1=minio.service_url(env["clusters"][0]), - minio_url_dr2=minio.service_url(env["clusters"][1]), - ) - kubectl.apply( - "--filename=-", - input=yaml, - context=env["hub"], - log=command.debug, + minio_url_dr1=minio.service_url(clusters[0]), + minio_url_dr2=minio.service_url(clusters[1]), ) - command.info("Creating DRClusters and DRPolicy for %s", env["topology"]) + +def apply_ramen_config_map(cluster, yaml): + command.info("Updating ramen config map in cluster '%s'", cluster) + kubectl.apply("--filename=-", input=yaml, context=cluster, log=command.debug) + + +def apply_dr_resources(hub, topology): + command.info("Creating DRClusters and DRPolicy for '%s'", topology) kubectl.apply( "--kustomize", - command.resource(env["topology"]), - context=env["hub"], + command.resource(topology), + context=hub, log=command.debug, ) + +def wait_for_dr_clusters(hub, clusters, args): command.info("Waiting until DRClusters report phase") - for name in env["clusters"]: + for name in clusters: drenv.wait_for( f"drcluster/{name}", output="jsonpath={.status.phase}", namespace=args.ramen_namespace, timeout=180, - profile=env["hub"], + profile=hub, log=command.debug, ) @@ -78,15 +101,17 @@ def run(args): "--all", "--for=jsonpath={.status.phase}=Available", f"--namespace={args.ramen_namespace}", - context=env["hub"], + context=hub, log=command.debug, ) + +def wait_for_dr_policy(hub, args): command.info("Waiting until DRPolicy is validated") kubectl.wait( "drpolicy/dr-policy", "--for=condition=Validated", f"--namespace={args.ramen_namespace}", - context=env["hub"], + context=hub, log=command.debug, ) 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/resources/configmap.yaml b/ramenctl/ramenctl/resources/configmap.yaml index 7b5dd1d1ed..fdb0a18fff 100644 --- a/ramenctl/ramenctl/resources/configmap.yaml +++ b/ramenctl/ramenctl/resources/configmap.yaml @@ -4,7 +4,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: ramen-hub-operator-config + name: $name namespace: ramen-system data: ramen_manager_config.yaml: | diff --git a/ramenctl/ramenctl/unconfig.py b/ramenctl/ramenctl/unconfig.py index dcd1a54191..da86c8c115 100644 --- a/ramenctl/ramenctl/unconfig.py +++ b/ramenctl/ramenctl/unconfig.py @@ -19,22 +19,32 @@ def register(commands): def run(args): env = command.env_info(args) - command.info("Deleting DRClusters and DRPolicy") + # Note: We keep the ramen config map since we do not own it. + if env["hub"]: + delete_dr_resources(env["hub"], env["topology"]) + delete_s3_secret(env["hub"]) + else: + for cluster in env["clusters"]: + delete_s3_secret(cluster) + + +def delete_dr_resources(hub, topology): + command.info("Deleting DRClusters and DRPolicy for '%s'", topology) kubectl.delete( "--kustomize", - command.resource(env["topology"]), + command.resource(topology), "--ignore-not-found", - context=env["hub"], + context=hub, log=command.debug, ) - # We keep the ramen config map since we do not own it. - command.info("Deleting s3 secret in ramen hub namespace") +def delete_s3_secret(cluster): + command.info("Deleting s3 secret in cluster '%s'", cluster) kubectl.delete( "--filename", command.resource("ramen-s3-secret.yaml"), "--ignore-not-found", - context=env["hub"], + context=cluster, log=command.debug, ) 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")