Skip to content

Commit

Permalink
Fix ramenctl [un]config with --name-prefix
Browse files Browse the repository at this point in the history
The cluster names were hard coded in the yamls, so configuring an
environment using --name-prefix was deploying drclusters and drpolicy
with the wrong cluster names.

Fix by removing the kustomization which does not work well for for our
use case. Instead the resources are now templates where we replace the
cluster names placeholders with the real cluster names before applying
the yaml directly.

With this change we can create an environment with --name-prefix and
then deploy and configure ramen with the same name prefix:

    (cd test && drenv start --name-prefix pr123- envs/regional-dr.yaml)
    ramenctl deploy --name-prefix pr123- envs/regional-dr.yaml
    ramenctl config --name-prefix pr123- envs/regional-dr.yaml

Part-of: RamenDR#959
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
  • Loading branch information
nirs committed Jul 9, 2023
1 parent 7de24ee commit df652f6
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 33 deletions.
26 changes: 17 additions & 9 deletions ramenctl/ramenctl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ def run(args):
template = drenv.template(command.resource("configmap.yaml"))
yaml = template.substitute(
auto_deploy="true",
minio_url_dr1=minio.service_url(env["clusters"][0]),
minio_url_dr2=minio.service_url(env["clusters"][1]),
cluster1=env["clusters"][0],
cluster2=env["clusters"][1],
minio_url_cluster1=minio.service_url(env["clusters"][0]),
minio_url_cluster2=minio.service_url(env["clusters"][1]),
)
kubectl.apply(
"--filename=-",
Expand All @@ -53,13 +55,19 @@ def run(args):
log=command.debug,
)

command.info("Creating DRClusters and DRPolicy for %s", env["topology"])
kubectl.apply(
"--kustomize",
command.resource(env["topology"]),
context=env["hub"],
log=command.debug,
)
for name in ["dr-clusters", "dr-policy"]:
command.info("Creating %s for %s", name, env["topology"])
template = drenv.template(command.resource(f"{env['topology']}/{name}.yaml"))
yaml = template.substitute(
cluster1=env["clusters"][0],
cluster2=env["clusters"][1],
)
kubectl.apply(
"--filename=-",
input=yaml,
context=env["hub"],
log=command.debug,
)

command.info("Waiting until DRClusters report phase")
for name in env["clusters"]:
Expand Down
8 changes: 4 additions & 4 deletions ramenctl/ramenctl/resources/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ data:
kubeObjectProtection:
veleroNamespaceName: velero
s3StoreProfiles:
- s3ProfileName: minio-on-dr1
- s3ProfileName: minio-on-$cluster1
s3Bucket: bucket
s3CompatibleEndpoint: $minio_url_dr1
s3CompatibleEndpoint: $minio_url_cluster1
s3Region: us-west-1
s3SecretRef:
name: ramen-s3-secret
namespace: ramen-system
veleroNamespaceSecretKeyRef:
key: cloud
name: cloud-credentials
- s3ProfileName: minio-on-dr2
- s3ProfileName: minio-on-$cluster2
s3Bucket: bucket
s3CompatibleEndpoint: $minio_url_dr2
s3CompatibleEndpoint: $minio_url_cluster2
s3Region: us-east-1
s3SecretRef:
name: ramen-s3-secret
Expand Down
8 changes: 4 additions & 4 deletions ramenctl/ramenctl/resources/regional-dr/dr-clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
apiVersion: ramendr.openshift.io/v1alpha1
kind: DRCluster
metadata:
name: dr1
name: $cluster1
spec:
s3ProfileName: minio-on-dr1
s3ProfileName: minio-on-$cluster1
region: west
---
apiVersion: ramendr.openshift.io/v1alpha1
kind: DRCluster
metadata:
name: dr2
name: $cluster2
spec:
s3ProfileName: minio-on-dr2
s3ProfileName: minio-on-$cluster2
region: east
4 changes: 2 additions & 2 deletions ramenctl/ramenctl/resources/regional-dr/dr-policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ metadata:
name: dr-policy
spec:
drClusters:
- dr1
- dr2
- $cluster1
- $cluster2
schedulingInterval: 1m
6 changes: 0 additions & 6 deletions ramenctl/ramenctl/resources/regional-dr/kustomization.yaml

This file was deleted.

24 changes: 16 additions & 8 deletions ramenctl/ramenctl/unconfig.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: The RamenDR authors
# SPDX-License-Identifier: Apache-2.0

import drenv
from drenv import kubectl

from . import command
Expand All @@ -19,14 +20,21 @@ def register(commands):
def run(args):
env = command.env_info(args)

command.info("Deleting DRClusters and DRPolicy")
kubectl.delete(
"--kustomize",
command.resource(env["topology"]),
"--ignore-not-found",
context=env["hub"],
log=command.debug,
)
# Deleting in reverse order.
for name in ["dr-policy", "dr-clusters"]:
command.info("Deleting %s for %s", name, env["topology"])
template = drenv.template(command.resource(f"{env['topology']}/{name}.yaml"))
yaml = template.substitute(
cluster1=env["clusters"][0],
cluster2=env["clusters"][1],
)
kubectl.delete(
"--filename=-",
"--ignore-not-found",
input=yaml,
context=env["hub"],
log=command.debug,
)

# We keep the ramen config map since we do not own it.

Expand Down

0 comments on commit df652f6

Please sign in to comment.