Skip to content

Commit

Permalink
Fix waiting until placement decision is available
Browse files Browse the repository at this point in the history
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: RamenDR#1562
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
  • Loading branch information
nirs committed Oct 29, 2024
1 parent b47caeb commit 8dbc62d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 47 deletions.
9 changes: 2 additions & 7 deletions e2e/dractions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := waitPlacementDecision(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")

Expand Down
12 changes: 0 additions & 12 deletions e2e/dractions/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
39 changes: 11 additions & 28 deletions e2e/dractions/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,28 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// nolint:gocognit
// return placementDecisionName, error
// waitPlacementDecision waits until we have a placement decision and returns the placement decision object.
func waitPlacementDecision(client client.Client, namespace string, placementName string,
) (string, error) {
) (*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) > 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(util.RetryInterval)
Expand Down Expand Up @@ -135,19 +125,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 := waitPlacementDecision(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
Expand Down

0 comments on commit 8dbc62d

Please sign in to comment.