From 9aa316ed211c516c593a6d6ce72487ed75b51bb1 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Mon, 28 Oct 2024 13:48:34 +0200 Subject: [PATCH] Fix waiting until placement decision is available We cannot use the method we used in drenv/test.lookup_cluster[1] since placement Satisfied condition is not set in discovered apps flows. Simplify the code to wait until we have placement decisions status contains non empty decisions list. [1] https://github.com/RamenDR/ramen/blob/2886c647e9c465f5fe7a8665e53c37de002b6326/test/drenv/test.py#L204 Fixes: #1562 Signed-off-by: Nir Soffer --- e2e/dractions/actions.go | 9 ++------- e2e/dractions/crud.go | 12 ------------ e2e/dractions/retry.go | 41 ++++++++++++---------------------------- 3 files changed, 14 insertions(+), 48 deletions(-) diff --git a/e2e/dractions/actions.go b/e2e/dractions/actions.go index 970166508..c70380fd2 100644 --- a/e2e/dractions/actions.go +++ b/e2e/dractions/actions.go @@ -43,18 +43,13 @@ func EnableProtection(w workloads.Workload, d deployers.Deployer) error { placementName := name drpcName := name - placementDecisionName, err := waitPlacementDecision(util.Ctx.Hub.CtrlClient, namespace, placementName) - if err != nil { - return err - } - - placementDecision, err := getPlacementDecision(util.Ctx.Hub.CtrlClient, namespace, placementDecisionName) + placementDecision, err := waitPlacmentDecision(util.Ctx.Hub.CtrlClient, namespace, placementName) if err != nil { return err } clusterName := placementDecision.Status.Decisions[0].ClusterName - util.Ctx.Log.Info("got clusterName " + clusterName + " from " + placementDecisionName) + util.Ctx.Log.Info("got clusterName " + clusterName + " from " + placementDecision.Name) util.Ctx.Log.Info("update placement " + placementName + " annotation") diff --git a/e2e/dractions/crud.go b/e2e/dractions/crud.go index ace684efe..b2867ae66 100644 --- a/e2e/dractions/crud.go +++ b/e2e/dractions/crud.go @@ -33,18 +33,6 @@ func updatePlacement(client client.Client, placement *clusterv1beta1.Placement) return client.Update(context.Background(), placement) } -func getPlacementDecision(client client.Client, namespace, name string) (*clusterv1beta1.PlacementDecision, error) { - placementDecision := &clusterv1beta1.PlacementDecision{} - key := types.NamespacedName{Namespace: namespace, Name: name} - - err := client.Get(context.Background(), key, placementDecision) - if err != nil { - return nil, err - } - - return placementDecision, nil -} - func getDRPC(client client.Client, namespace, name string) (*ramen.DRPlacementControl, error) { drpc := &ramen.DRPlacementControl{} key := types.NamespacedName{Namespace: namespace, Name: name} diff --git a/e2e/dractions/retry.go b/e2e/dractions/retry.go index b85af0be0..582dd64c4 100644 --- a/e2e/dractions/retry.go +++ b/e2e/dractions/retry.go @@ -15,38 +15,28 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -// nolint:gocognit -// return placementDecisionName, error -func waitPlacementDecision(client client.Client, namespace string, placementName string, -) (string, error) { +// waitPlacementDecsision waits until we have placemnt desicion and return the placmenet decision object. +func waitPlacmentDecision(client client.Client, namespace string, placementName string, +) (*v1beta1.PlacementDecision, error) { startTime := time.Now() - placementDecisionName := "" for { placement, err := getPlacement(client, namespace, placementName) if err != nil { - return "", err + return nil, err } - for _, cond := range placement.Status.Conditions { - if cond.Type == "PlacementSatisfied" && cond.Status == "True" { - placementDecisionName = placement.Status.DecisionGroups[0].Decisions[0] - if placementDecisionName != "" { - return placementDecisionName, nil - } - } + placementDecision, err := getPlacementDecisionFromPlacement(client, placement) + if err != nil { + return nil, err } - // if placement is controlled by ramen, it will not have placementdecision name in its status - // so need query placementdecision by label - placementDecision, err := getPlacementDecisionFromPlacement(client, placement) - if err == nil && placementDecision != nil { - return placementDecision.Name, nil + if placementDecision != nil && len(placementDecision.Status.Decisions) > 0 { + return placementDecision, nil } if time.Since(startTime) > time.Second*time.Duration(util.Timeout) { - return "", fmt.Errorf( - "could not get placement decision for " + placementName + " before timeout, fail") + return nil, fmt.Errorf("timeout waiting for placement decisions for %q ", placementName) } time.Sleep(time.Second * time.Duration(util.TimeInterval)) @@ -136,19 +126,12 @@ func waitDRPCPhase(client client.Client, namespace, name string, phase ramen.DRS } func getCurrentCluster(client client.Client, namespace string, placementName string) (string, error) { - placementDecisionName, err := waitPlacementDecision(client, namespace, placementName) + placementDecision, err := waitPlacmentDecision(client, namespace, placementName) if err != nil { return "", err } - placementDecision, err := getPlacementDecision(client, namespace, placementDecisionName) - if err != nil { - return "", err - } - - clusterName := placementDecision.Status.Decisions[0].ClusterName - - return clusterName, nil + return placementDecision.Status.Decisions[0].ClusterName, nil } // return dr cluster client