From 31fc932fbca971d1c1d35410d2d7e3eb2a6557f3 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Thu, 5 Oct 2023 16:05:35 +0300 Subject: [PATCH] Replace PlacementRule with Placement PlacementRule is deprecated and replaced by Placement in OpenShift for a while. We want to test only Placement, so testing with upstream is more likely to reveal issues with OpenShift. This change should be merge together with this ocm-ramen-samples PR: https://github.com/RamenDR/ocm-ramen-samples/pull/39 Signed-off-by: Nir Soffer --- test/drenv/test.py | 92 +++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 59 deletions(-) diff --git a/test/drenv/test.py b/test/drenv/test.py index 2d3a4dafa..34be0c676 100644 --- a/test/drenv/test.py +++ b/test/drenv/test.py @@ -22,6 +22,10 @@ parser = None log_format = "%(asctime)s %(levelname)-7s [%(name)s] %(message)s" +OCM_SCHEDULING_DISABLE = ( + "cluster.open-cluster-management.io/experimental-scheduling-disable" +) + def start(name, file, config_file="config.yaml"): global workdir, config, parser, log @@ -134,11 +138,21 @@ def enable_dr(): """ Enable DR for deployed application. """ - cluster = lookup_cluster() + placement = _lookup_app_resource("placement") + if not placement: + raise RuntimeError(f"Cannot find placement for application {config['name']}") - # TODO: support placement - info("Setting placementrule scheduler to ramen") - _patch_placementrule({"spec": {"schedulerName": "ramen"}}) + info("Disabling OCM scheduling for '%s'", placement) + kubectl.annotate( + placement, + {OCM_SCHEDULING_DISABLE: "true"}, + namespace=config["namespace"], + context=env["hub"], + log=debug, + ) + + cluster = lookup_cluster() + placement_name = placement.split("/")[1] drpc = f""" apiVersion: ramendr.openshift.io/v1alpha1 @@ -153,8 +167,8 @@ def enable_dr(): drPolicyRef: name: dr-policy placementRef: - kind: PlacementRule - name: busybox-placement + kind: Placement + name: {placement_name} pvcSelector: matchLabels: appname: busybox @@ -180,24 +194,16 @@ def disable_dr(): log=debug, ) - # TODO: support placement - info("Clearing placementrule scheduler") - _patch_placementrule({"spec": {"schedulerName": None}}) - - -def _patch_placementrule(patch): - placementrule = _lookup_app_resource("placementrule") - if not placementrule: - raise RuntimeError( - f"Cannot find placementrule for application {config['name']}" - ) + placement = _lookup_app_resource("placement") + if not placement: + debug("placement already removed") + return - kubectl.patch( - placementrule, - "--patch", - json.dumps(patch), - "--type=merge", - f"--namespace={config['namespace']}", + info("Enabling OCM scheduling for '%s'", placement) + kubectl.annotate( + placement, + {OCM_SCHEDULING_DISABLE: None}, + namespace=config["namespace"], context=env["hub"], log=debug, ) @@ -218,25 +224,16 @@ def lookup_cluster(): """ Return the current cluster the application is placed on. """ - cluster = _get_cluster_from_placement_decisions() - if not cluster: - cluster = _get_cluster_from_placementrule() - if not cluster: - raise RuntimeError(f"Cannot find cluster for application {config['name']}") - - return cluster - - -def _get_cluster_from_placement_decisions(): placement = _lookup_app_resource("placement") if not placement: - return None + raise RuntimeError(f"Cannot find placement for application {config['name']}") info("Waiting for '%s' decisions", placement) kubectl.wait( placement, "--for=condition=PlacementSatisfied", "--timeout=60s", + f"--namespace={config['namespace']}", context=env["hub"], log=debug, ) @@ -245,32 +242,9 @@ def _get_cluster_from_placement_decisions(): return kubectl.get( "placementdecisions", - f"--selector=cluster.open-cluster-management.io/placement={placement_name}" - f"--namespace={config['namespace']}", - "--output=jsonpath={.status.decisions[0].clusterName}", - context=env["hub"], - ) - - -def _get_cluster_from_placementrule(): - placementrule = _lookup_app_resource("placementrule") - if not placementrule: - return None - - info("Waiting for '%s' decisions", placementrule) - drenv.wait_for( - placementrule, - output="jsonpath={.status.decisions}", - namespace=config["namespace"], - timeout=60, - profile=env["hub"], - log=debug, - ) - - return kubectl.get( - placementrule, + f"--selector=cluster.open-cluster-management.io/placement={placement_name}", f"--namespace={config['namespace']}", - "--output=jsonpath={.status.decisions[0].clusterName}", + "--output=jsonpath={.items[0].status.decisions[0].clusterName}", context=env["hub"], )