Skip to content

Commit

Permalink
Simplify waitPlacementDecision
Browse files Browse the repository at this point in the history
It was returning both placement and placementDecsision name which is not
helpful since we have a helper to return a placement.

Signed-off-by: Nir Soffer <[email protected]>
  • Loading branch information
nirs authored and raghavendra-talur committed Oct 23, 2024
1 parent f2ba011 commit ec7c087
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion e2e/dractions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func EnableProtection(w workloads.Workload, d deployers.Deployer) error {
placementName := name
drpcName := name

placement, placementDecisionName, err := waitPlacementDecision(util.Ctx.Hub.CtrlClient, namespace, placementName)
placementDecisionName, err := waitPlacementDecision(util.Ctx.Hub.CtrlClient, namespace, placementName)
if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions e2e/dractions/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ import (
)

// nolint:gocognit
// return placement object, placementDecisionName, error
// return placementDecisionName, error
func waitPlacementDecision(client client.Client, namespace string, placementName string,
) (*v1beta1.Placement, string, error) {
) (string, error) {
startTime := time.Now()
placementDecisionName := ""

for {
placement, err := getPlacement(client, namespace, placementName)
if err != nil {
return nil, "", err
return "", err
}

for _, cond := range placement.Status.Conditions {
if cond.Type == "PlacementSatisfied" && cond.Status == "True" {
placementDecisionName = placement.Status.DecisionGroups[0].Decisions[0]
if placementDecisionName != "" {
return placement, placementDecisionName, nil
return placementDecisionName, nil
}
}
}
Expand All @@ -41,11 +41,11 @@ func waitPlacementDecision(client client.Client, namespace string, placementName
// so need query placementdecision by label
placementDecision, err := getPlacementDecisionFromPlacement(client, placement)
if err == nil && placementDecision != nil {
return placement, placementDecision.Name, nil
return placementDecision.Name, nil
}

if time.Since(startTime) > time.Second*time.Duration(util.Timeout) {
return nil, "", fmt.Errorf(
return "", fmt.Errorf(
"could not get placement decision for " + placementName + " before timeout, fail")
}

Expand Down Expand Up @@ -136,7 +136,7 @@ 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)
placementDecisionName, err := waitPlacementDecision(client, namespace, placementName)
if err != nil {
return "", err
}
Expand Down

0 comments on commit ec7c087

Please sign in to comment.