From 797475c53ff04b72e1d85a1601010bad7b89bfa4 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Mon, 21 Oct 2024 23:38:05 +0300 Subject: [PATCH] Handle conflicts when starting failover or relocate Fix random failures like: actions_test.go:53: Operation cannot be fulfilled on drplacementcontrols.ramendr.openshift.io "subscr-deploy-rbd-busybox": the object has been modified; please apply your changes to the latest version and try again Signed-off-by: Nir Soffer --- e2e/dractions/actions.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/e2e/dractions/actions.go b/e2e/dractions/actions.go index 406fc819a..970166508 100644 --- a/e2e/dractions/actions.go +++ b/e2e/dractions/actions.go @@ -165,11 +165,6 @@ func waitAndUpdateDRPC(client client.Client, namespace, drpcName string, action return err } - drpc, err := getDRPC(client, namespace, drpcName) - if err != nil { - return err - } - drPolicyName := util.DefaultDRPolicyName drpolicy, err := util.GetDRPolicy(client, drPolicyName) @@ -182,16 +177,23 @@ func waitAndUpdateDRPC(client client.Client, namespace, drpcName string, action return err } - drpc.Spec.Action = action - if action == ramen.ActionFailover { - drpc.Spec.FailoverCluster = targetCluster - } else { - drpc.Spec.PreferredCluster = targetCluster - } - util.Ctx.Log.Info("update drpc " + drpcName + " " + strings.ToLower(string(action)) + " to " + targetCluster) - return updateDRPC(client, drpc) + return retry.RetryOnConflict(retry.DefaultBackoff, func() error { + drpc, err := getDRPC(client, namespace, drpcName) + if err != nil { + return err + } + + drpc.Spec.Action = action + if action == ramen.ActionFailover { + drpc.Spec.FailoverCluster = targetCluster + } else { + drpc.Spec.PreferredCluster = targetCluster + } + + return updateDRPC(client, drpc) + }) } func GetNamespace(d deployers.Deployer, w workloads.Workload) string {