From 65558bd64612ec49e6386ea2242ebd4bc3b5aab5 Mon Sep 17 00:00:00 2001 From: ChrisLiu <70144550+chrisliu1995@users.noreply.github.com> Date: Wed, 5 Jul 2023 11:35:11 +0800 Subject: [PATCH] add reserveIds when init asts (#73) Signed-off-by: ChrisLiu --- .../gameserverset/gameserverset_controller.go | 1 + .../gameserverset_manager_test.go | 28 +++++++++++++++++++ pkg/util/slice_test.go | 5 ++++ 3 files changed, 34 insertions(+) diff --git a/pkg/controllers/gameserverset/gameserverset_controller.go b/pkg/controllers/gameserverset/gameserverset_controller.go index 520b3eb..77b921d 100644 --- a/pkg/controllers/gameserverset/gameserverset_controller.go +++ b/pkg/controllers/gameserverset/gameserverset_controller.go @@ -286,6 +286,7 @@ func (r *GameServerSetReconciler) initAsts(gss *gamekruiseiov1alpha1.GameServerS // set replicas asts.Spec.Replicas = gss.Spec.Replicas + asts.Spec.ReserveOrdinals = gss.Spec.ReserveGameServerIds asts = util.GetNewAstsFromGss(gss.DeepCopy(), asts) diff --git a/pkg/controllers/gameserverset/gameserverset_manager_test.go b/pkg/controllers/gameserverset/gameserverset_manager_test.go index 69206d1..00f35c9 100644 --- a/pkg/controllers/gameserverset/gameserverset_manager_test.go +++ b/pkg/controllers/gameserverset/gameserverset_manager_test.go @@ -296,6 +296,34 @@ func TestComputeToScaleGs(t *testing.T) { }, newReserveIds: []int{0, 3, 5, 2, 4, 6}, }, + { + newGssReserveIds: []int{1, 2}, + oldGssreserveIds: []int{}, + notExistIds: []int{1, 2}, + expectedReplicas: 2, + scaleDownStrategyType: gameKruiseV1alpha1.GeneralScaleDownStrategyType, + pods: []corev1.Pod{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "xxx-0", + Labels: map[string]string{ + gameKruiseV1alpha1.GameServerOpsStateKey: string(gameKruiseV1alpha1.None), + gameKruiseV1alpha1.GameServerDeletePriorityKey: "0", + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "xxx-3", + Labels: map[string]string{ + gameKruiseV1alpha1.GameServerOpsStateKey: string(gameKruiseV1alpha1.None), + gameKruiseV1alpha1.GameServerDeletePriorityKey: "0", + }, + }, + }, + }, + newReserveIds: []int{1, 2}, + }, } for i, test := range tests { diff --git a/pkg/util/slice_test.go b/pkg/util/slice_test.go index 2705e2a..22e1dff 100644 --- a/pkg/util/slice_test.go +++ b/pkg/util/slice_test.go @@ -73,6 +73,11 @@ func TestGetSliceInANotInB(t *testing.T) { b: []int{1, 2, 3}, result: []int{4, 5}, }, + { + a: []int{1, 2}, + b: []int{}, + result: []int{1, 2}, + }, } for _, test := range tests {