Skip to content

Commit

Permalink
revert placement decision start index from 1 to keep backward compati…
Browse files Browse the repository at this point in the history
…bility

Signed-off-by: haoqing0110 <qhao@redhat.com>
  • Loading branch information
haoqing0110 committed Aug 22, 2023
1 parent 4227c8f commit 5ed14c4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
17 changes: 6 additions & 11 deletions pkg/placement/controllers/scheduling/schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package scheduling
import (
"context"
"encoding/json"
"fmt"
"reflect"
"sort"
"testing"
Expand Down Expand Up @@ -148,7 +147,7 @@ func TestSchedule(t *testing.T) {
initObjs: []runtime.Object{
testinghelpers.NewClusterSet(clusterSetName).Build(),
testinghelpers.NewClusterSetBinding(placementNamespace, clusterSetName),
testinghelpers.NewPlacementDecision(placementNamespace, placementDecisionName(placementName, 1)).
testinghelpers.NewPlacementDecision(placementNamespace, testinghelpers.PlacementDecisionName(placementName, 1)).
WithLabel(clusterapiv1beta1.PlacementLabel, placementName).
WithDecisions("cluster1", "cluster2").Build(),
},
Expand Down Expand Up @@ -420,7 +419,7 @@ func TestSchedule(t *testing.T) {
initObjs: []runtime.Object{
testinghelpers.NewClusterSet(clusterSetName).Build(),
testinghelpers.NewClusterSetBinding(placementNamespace, clusterSetName),
testinghelpers.NewPlacementDecision(placementNamespace, placementDecisionName(placementName, 1)).
testinghelpers.NewPlacementDecision(placementNamespace, testinghelpers.PlacementDecisionName(placementName, 1)).
WithLabel(clusterapiv1beta1.PlacementLabel, placementName).
WithDecisions("cluster1").Build(),
},
Expand Down Expand Up @@ -467,7 +466,7 @@ func TestSchedule(t *testing.T) {
initObjs: []runtime.Object{
testinghelpers.NewClusterSet(clusterSetName).Build(),
testinghelpers.NewClusterSetBinding(placementNamespace, clusterSetName),
testinghelpers.NewPlacementDecision(placementNamespace, placementDecisionName("others", 1)).
testinghelpers.NewPlacementDecision(placementNamespace, testinghelpers.PlacementDecisionName("others", 1)).
WithDecisions("cluster1", "cluster2").Build(),
},
clusters: []*clusterapiv1.ManagedCluster{
Expand Down Expand Up @@ -513,11 +512,11 @@ func TestSchedule(t *testing.T) {
initObjs: []runtime.Object{
testinghelpers.NewClusterSet(clusterSetName).Build(),
testinghelpers.NewClusterSetBinding(placementNamespace, clusterSetName),
testinghelpers.NewPlacementDecision(placementNamespace, placementDecisionName("others", 1)).
testinghelpers.NewPlacementDecision(placementNamespace, testinghelpers.PlacementDecisionName("others", 1)).
WithDecisions("cluster2", "cluster3").Build(),
testinghelpers.NewPlacementDecision(placementNamespace, placementDecisionName("others", 2)).
testinghelpers.NewPlacementDecision(placementNamespace, testinghelpers.PlacementDecisionName("others", 2)).
WithDecisions("cluster1", "cluster2").Build(),
testinghelpers.NewPlacementDecision(placementNamespace, placementDecisionName(placementName, 1)).
testinghelpers.NewPlacementDecision(placementNamespace, testinghelpers.PlacementDecisionName(placementName, 1)).
WithLabel(clusterapiv1beta1.PlacementLabel, placementName).
WithDecisions("cluster3").Build(),
},
Expand Down Expand Up @@ -605,10 +604,6 @@ func TestSchedule(t *testing.T) {
}
}

func placementDecisionName(placementName string, index int) string {
return fmt.Sprintf("%s-decision-%d", placementName, index)
}

func TestFilterResults(t *testing.T) {

}
5 changes: 3 additions & 2 deletions pkg/placement/controllers/scheduling/scheduling_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func (c *schedulingController) generatePlacementDecisionsAndStatus(
placement *clusterapiv1beta1.Placement,
clusters []*clusterapiv1.ManagedCluster,
) ([]*clusterapiv1beta1.PlacementDecision, []*clusterapiv1beta1.DecisionGroupStatus, *framework.Status) {
placementDecisionIndex := 0
placementDecisionIndex := 1
var placementDecisions []*clusterapiv1beta1.PlacementDecision
var decisionGroupStatus []*clusterapiv1beta1.DecisionGroupStatus

Expand All @@ -465,7 +465,8 @@ func (c *schedulingController) generatePlacementDecisionsAndStatus(

// generate placement decision for each decision group
for decisionGroupIndex, decisionGroup := range decisionGroups {
// generate placement decisions and status, group and placement name index starts from 0.
// generate placement decisions and status, group name index starts from 0, placement name index
// starts from 1 to keep backward compatibility.
pds, groupStatus := c.generateDecision(placement, decisionGroup, decisionGroupIndex, placementDecisionIndex)

placementDecisions = append(placementDecisions, pds...)
Expand Down
36 changes: 18 additions & 18 deletions pkg/placement/controllers/scheduling/scheduling_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestSchedulingController_sync(t *testing.T) {
{
DecisionGroupIndex: 0,
DecisionGroupName: "",
Decisions: []string{"placement1-decision-0"},
Decisions: []string{testinghelpers.PlacementDecisionName(placementName, 1)},
ClustersCount: 3,
},
}
Expand Down Expand Up @@ -194,25 +194,25 @@ func TestSchedulingController_sync(t *testing.T) {
{
DecisionGroupIndex: 0,
DecisionGroupName: "canary",
Decisions: []string{"placement1-decision-0"},
Decisions: []string{testinghelpers.PlacementDecisionName(placementName, 1)},
ClustersCount: 1,
},
{
DecisionGroupIndex: 1,
DecisionGroupName: "canary",
Decisions: []string{"placement1-decision-1"},
Decisions: []string{testinghelpers.PlacementDecisionName(placementName, 2)},
ClustersCount: 1,
},
{
DecisionGroupIndex: 2,
DecisionGroupName: "",
Decisions: []string{"placement1-decision-2"},
Decisions: []string{testinghelpers.PlacementDecisionName(placementName, 3)},
ClustersCount: 1,
},
{
DecisionGroupIndex: 3,
DecisionGroupName: "",
Decisions: []string{"placement1-decision-3"},
Decisions: []string{testinghelpers.PlacementDecisionName(placementName, 4)},
ClustersCount: 1,
},
}
Expand Down Expand Up @@ -276,13 +276,13 @@ func TestSchedulingController_sync(t *testing.T) {
{
DecisionGroupIndex: 0,
DecisionGroupName: "group1",
Decisions: []string{"placement1-decision-0"},
Decisions: []string{testinghelpers.PlacementDecisionName(placementName, 1)},
ClustersCount: 2,
},
{
DecisionGroupIndex: 1,
DecisionGroupName: "group2",
Decisions: []string{"placement1-decision-1"},
Decisions: []string{testinghelpers.PlacementDecisionName(placementName, 2)},
ClustersCount: 1,
},
}
Expand Down Expand Up @@ -334,19 +334,19 @@ func TestSchedulingController_sync(t *testing.T) {
{
DecisionGroupIndex: 0,
DecisionGroupName: "",
Decisions: []string{"placement1-decision-0"},
Decisions: []string{testinghelpers.PlacementDecisionName(placementName, 1)},
ClustersCount: 1,
},
{
DecisionGroupIndex: 1,
DecisionGroupName: "",
Decisions: []string{"placement1-decision-1"},
Decisions: []string{testinghelpers.PlacementDecisionName(placementName, 2)},
ClustersCount: 1,
},
{
DecisionGroupIndex: 2,
DecisionGroupName: "",
Decisions: []string{"placement1-decision-2"},
Decisions: []string{testinghelpers.PlacementDecisionName(placementName, 3)},
ClustersCount: 1,
},
}
Expand Down Expand Up @@ -510,7 +510,7 @@ func TestSchedulingController_sync(t *testing.T) {
testinghelpers.NewClusterSet("clusterset1").Build(),
testinghelpers.NewClusterSetBinding(placementNamespace, "clusterset1"),
testinghelpers.NewManagedCluster("cluster1").WithLabel(clusterapiv1beta2.ClusterSetLabel, "clusterset1").Build(),
testinghelpers.NewPlacementDecision(placementNamespace, placementDecisionName(placementName, 0)).
testinghelpers.NewPlacementDecision(placementNamespace, testinghelpers.PlacementDecisionName(placementName, 1)).
WithLabel(clusterapiv1beta1.PlacementLabel, placementName).
WithLabel(clusterapiv1beta1.DecisionGroupNameLabel, "").
WithLabel(clusterapiv1beta1.DecisionGroupIndexLabel, "0").
Expand Down Expand Up @@ -1265,12 +1265,12 @@ func TestBind(t *testing.T) {
placement: testinghelpers.NewPlacement(placementNamespace, placementName).Build(),
clusters: newClusters(128),
initObjs: []runtime.Object{
testinghelpers.NewPlacementDecision(placementNamespace, placementDecisionName(placementName, 0)).
testinghelpers.NewPlacementDecision(placementNamespace, testinghelpers.PlacementDecisionName(placementName, 1)).
WithLabel(clusterapiv1beta1.PlacementLabel, placementName).
WithLabel(clusterapiv1beta1.DecisionGroupNameLabel, "").
WithLabel(clusterapiv1beta1.DecisionGroupIndexLabel, "0").
WithDecisions(newSelectedClusters(128)[:100]...).Build(),
testinghelpers.NewPlacementDecision(placementNamespace, placementDecisionName(placementName, 1)).
testinghelpers.NewPlacementDecision(placementNamespace, testinghelpers.PlacementDecisionName(placementName, 2)).
WithLabel(clusterapiv1beta1.PlacementLabel, placementName).
WithLabel(clusterapiv1beta1.DecisionGroupNameLabel, "").
WithLabel(clusterapiv1beta1.DecisionGroupIndexLabel, "0").
Expand All @@ -1283,7 +1283,7 @@ func TestBind(t *testing.T) {
placement: testinghelpers.NewPlacement(placementNamespace, placementName).Build(),
clusters: newClusters(128),
initObjs: []runtime.Object{
testinghelpers.NewPlacementDecision(placementNamespace, placementDecisionName(placementName, 0)).
testinghelpers.NewPlacementDecision(placementNamespace, testinghelpers.PlacementDecisionName(placementName, 1)).
WithLabel(clusterapiv1beta1.PlacementLabel, placementName).
WithLabel(clusterapiv1beta1.DecisionGroupNameLabel, "fakegroup").
WithLabel(clusterapiv1beta1.DecisionGroupIndexLabel, "0").
Expand Down Expand Up @@ -1317,12 +1317,12 @@ func TestBind(t *testing.T) {
placement: testinghelpers.NewPlacement(placementNamespace, placementName).Build(),
clusters: newClusters(10),
initObjs: []runtime.Object{
testinghelpers.NewPlacementDecision(placementNamespace, placementDecisionName(placementName, 0)).
testinghelpers.NewPlacementDecision(placementNamespace, testinghelpers.PlacementDecisionName(placementName, 1)).
WithLabel(clusterapiv1beta1.PlacementLabel, placementName).
WithLabel(clusterapiv1beta1.DecisionGroupNameLabel, "").
WithLabel(clusterapiv1beta1.DecisionGroupIndexLabel, "0").
WithDecisions(newSelectedClusters(128)[:100]...).Build(),
testinghelpers.NewPlacementDecision(placementNamespace, placementDecisionName(placementName, 1)).
testinghelpers.NewPlacementDecision(placementNamespace, testinghelpers.PlacementDecisionName(placementName, 2)).
WithLabel(clusterapiv1beta1.PlacementLabel, placementName).
WithLabel(clusterapiv1beta1.DecisionGroupNameLabel, "").
WithLabel(clusterapiv1beta1.DecisionGroupIndexLabel, "0").
Expand All @@ -1344,12 +1344,12 @@ func TestBind(t *testing.T) {
placement: testinghelpers.NewPlacement(placementNamespace, placementName).Build(),
clusters: newClusters(0),
initObjs: []runtime.Object{
testinghelpers.NewPlacementDecision(placementNamespace, placementDecisionName(placementName, 0)).
testinghelpers.NewPlacementDecision(placementNamespace, testinghelpers.PlacementDecisionName(placementName, 1)).
WithLabel(clusterapiv1beta1.PlacementLabel, placementName).
WithLabel(clusterapiv1beta1.DecisionGroupNameLabel, "").
WithLabel(clusterapiv1beta1.DecisionGroupIndexLabel, "0").
WithDecisions(newSelectedClusters(128)[:100]...).Build(),
testinghelpers.NewPlacementDecision(placementNamespace, placementDecisionName(placementName, 1)).
testinghelpers.NewPlacementDecision(placementNamespace, testinghelpers.PlacementDecisionName(placementName, 2)).
WithLabel(clusterapiv1beta1.PlacementLabel, placementName).
WithLabel(clusterapiv1beta1.DecisionGroupNameLabel, "").
WithLabel(clusterapiv1beta1.DecisionGroupIndexLabel, "0").
Expand Down
6 changes: 5 additions & 1 deletion pkg/placement/helpers/testing/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (b *PlacementBuilder) WithNumOfSelectedClusters(nosc int, placementName str
DecisionGroupIndex: 0,
DecisionGroupName: "",
ClustersCount: int32(nosc),
Decisions: []string{fmt.Sprintf("%s-decision-%d", placementName, 0)},
Decisions: []string{PlacementDecisionName(placementName, 1)},
},
}
return b
Expand Down Expand Up @@ -375,3 +375,7 @@ func (a *AddOnPlacementScoreBuilder) WithValidUntil(validUntil time.Time) *AddOn
func (a *AddOnPlacementScoreBuilder) Build() *clusterapiv1alpha1.AddOnPlacementScore {
return a.addOnPlacementScore
}

func PlacementDecisionName(placementName string, index int) string {
return fmt.Sprintf("%s-decision-%d", placementName, index)
}

0 comments on commit 5ed14c4

Please sign in to comment.