Skip to content

Commit

Permalink
Support hubless environment in ramenctl
Browse files Browse the repository at this point in the history
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 <nsoffer@redhat.com>
  • Loading branch information
nirs committed Jul 20, 2023
1 parent ff8dbdd commit 05ce848
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
27 changes: 18 additions & 9 deletions ramenctl/ramenctl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 9 additions & 5 deletions ramenctl/ramenctl/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 18 additions & 12 deletions ramenctl/ramenctl/unconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions ramenctl/ramenctl/undeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 05ce848

Please sign in to comment.