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 28, 2024
1 parent 2886c64 commit 9aa316e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 48 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 := 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")

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
41 changes: 12 additions & 29 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
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))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9aa316e

Please sign in to comment.