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 config` installs the s3 secret and
  ramen-dr-cluster-operator-config map on the dr clusters.
- `ramenctl unconfig` skips the hub configuration and delete the s3
  secrets from the dr clusters.
- `ramenctl undeploy` skips the hub deployment

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
  • Loading branch information
nirs committed Jul 5, 2023
1 parent c669b6e commit 0c478c0
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 35 deletions.
65 changes: 45 additions & 20 deletions ramenctl/ramenctl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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,
)
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
2 changes: 1 addition & 1 deletion ramenctl/ramenctl/resources/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: ramen-hub-operator-config
name: $name
namespace: ramen-system
data:
ramen_manager_config.yaml: |
Expand Down
22 changes: 16 additions & 6 deletions ramenctl/ramenctl/unconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
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 0c478c0

Please sign in to comment.