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 Jun 2, 2023
1 parent 0ce8c1c commit c122caa
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 37 deletions.
70 changes: 49 additions & 21 deletions ramenctl/ramenctl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,78 @@ def register(commands):
def run(args):
env = command.env_info(args)

if env["hub"]:
wait_for_ramen_hub_operator(env["hub"])
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"])
wait_for_dr_policy(env["hub"])
apply_sample_channel(env["hub"])
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):
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):
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,23 +102,27 @@ 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):
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,
)


def apply_sample_channel(hub):
command.info("Creating channel")
kubectl.apply(
"--filename",
command.resource("samples-channel.yaml"),
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
27 changes: 20 additions & 7 deletions ramenctl/ramenctl/unconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,44 @@ def register(commands):
def run(args):
env = command.env_info(args)

# Note: We keep the ramen config map since we do not own it.
if env["hub"]:
delete_sample_channel(env["hub"])
delete_dr_resources(env["hub"], env["toplogy"])
delete_s3_secret(env["hub"])
else:
for cluster in env["clusters"]:
delete_s3_secret(cluster)


def delete_sample_channel(hub):
command.info("Deleting samples channel")
kubectl.delete(
"--filename",
command.resource("samples-channel.yaml"),
"--ignore-not-found",
context=env["hub"],
context=hub,
log=command.debug,
)

command.info("Deleting DRClusters and DRPolicy")

def delete_dr_resources(hub, topology):
command.info(f"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 c122caa

Please sign in to comment.