diff --git a/pkg/gameserversets/controller.go b/pkg/gameserversets/controller.go index 10b49224c2..0fc803b786 100644 --- a/pkg/gameserversets/controller.go +++ b/pkg/gameserversets/controller.go @@ -460,7 +460,7 @@ func computeReconciliationAction(gsSet *v1alpha1.GameServerSet, list []*v1alpha1 if gsSet.Spec.Scheduling == v1alpha1.Packed { potentialDeletions = sortGameServersByLeastFullNodes(potentialDeletions, counts) } else { - // TODO: sortGameServersByNewFirst + potentialDeletions = sortGameServersByNewFirst(potentialDeletions) } toDelete = append(toDelete, potentialDeletions[0:deleteCount]...) diff --git a/pkg/gameserversets/controller_test.go b/pkg/gameserversets/controller_test.go index c04aab598e..8e16a62eaa 100644 --- a/pkg/gameserversets/controller_test.go +++ b/pkg/gameserversets/controller_test.go @@ -172,14 +172,28 @@ func TestComputeReconciliationAction(t *testing.T) { }) } - /* - TODO: make these tests work - t.Run("test packed scale down", func(t *testing.T) { - gsSet := &v1alpha1.GameServerSet{Spec: v1alpha1.GameServerSetSpec{Scheduling: v1alpha1.Packed}} + t.Run("test packed scale down", func(t *testing.T) { + gsSet := &v1alpha1.GameServerSet{Spec: v1alpha1.GameServerSetSpec{Replicas: 2, Scheduling: v1alpha1.Packed}} - toAdd, toDelete, isPartial := computeReconciliationAction(gsSet, ) - }) + list := []*v1alpha1.GameServer{ + {ObjectMeta: metav1.ObjectMeta{Name: "gs1"}, Status: v1alpha1.GameServerStatus{State: v1alpha1.GameServerStateReady, NodeName: "node3"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "gs2"}, Status: v1alpha1.GameServerStatus{State: v1alpha1.GameServerStateReady, NodeName: "node1"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "gs3"}, Status: v1alpha1.GameServerStatus{State: v1alpha1.GameServerStateReady, NodeName: "node3"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "gs4"}, Status: v1alpha1.GameServerStatus{State: v1alpha1.GameServerStateReady, NodeName: ""}}, + } + + counts := map[string]gameservers.NodeCount{"node1": {Ready: 1}, "node3": {Ready: 2}} + toAdd, toDelete, isPartial := computeReconciliationAction(gsSet, list, counts, int(gsSet.Spec.Replicas), 1000, 1000, 1000) + assert.Empty(t, toAdd) + assert.False(t, isPartial, "shouldn't be partial") + assert.Len(t, toDelete, 2) + assert.Equal(t, "gs4", toDelete[0].ObjectMeta.Name) + assert.Equal(t, "gs2", toDelete[1].ObjectMeta.Name) + }) + + //TODO: make these tests work + /* t.Run("test distributed scale down", func(t *testing.T) { gsSet := &v1alpha1.GameServerSet{Spec: v1alpha1.GameServerSetSpec{Scheduling: v1alpha1.Packed}}