From 1b05801484287ed7e69bf7ec6a5562b98cfdcef0 Mon Sep 17 00:00:00 2001 From: ChrisLiu <70144550+chrisliu1995@users.noreply.github.com> Date: Fri, 28 Jul 2023 14:49:20 +0800 Subject: [PATCH] feat: add new opsState named Allocated (#89) Signed-off-by: ChrisLiu --- apis/v1alpha1/gameserver_types.go | 1 + docs/en/getting_started/gameservers_scale.md | 2 +- docs/中文/快速开始/游戏服水平伸缩.md | 2 +- pkg/util/gameserver.go | 4 +- pkg/util/gameserver_test.go | 41 ++++++++++++++++++++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/apis/v1alpha1/gameserver_types.go b/apis/v1alpha1/gameserver_types.go index 02952c6..64b3379 100644 --- a/apis/v1alpha1/gameserver_types.go +++ b/apis/v1alpha1/gameserver_types.go @@ -61,6 +61,7 @@ const ( Maintaining OpsState = "Maintaining" WaitToDelete OpsState = "WaitToBeDeleted" None OpsState = "None" + Allocated OpsState = "Allocated" ) type ServiceQuality struct { diff --git a/docs/en/getting_started/gameservers_scale.md b/docs/en/getting_started/gameservers_scale.md index 358617a..6781169 100644 --- a/docs/en/getting_started/gameservers_scale.md +++ b/docs/en/getting_started/gameservers_scale.md @@ -2,7 +2,7 @@ OpenKruiseGame allows you to set the states of game servers. You can manually set the value of opsState or DeletionPriority for a game server. You can also use the service quality feature to automatically set the value of opsState or DeletionPriority for a game server. During scale-in, a proper GameServerSet workload is selected for scale-in based on the states of game servers. The scale-in rules are as follows: -1. Scale in game servers based on the opsState values. Scale in the game servers for which the opsState values are `WaitToBeDeleted`, `None`, and `Maintaining` in sequence. +1. Scale in game servers based on the opsState values. Scale in the game servers for which the opsState values are `WaitToBeDeleted`, `None`, `Allocated`, and `Maintaining` in sequence. 2. If two or more game servers have the same opsState value, game servers are performed based on the values of DeletionPriority. The game server with the largest DeletionPriority value is deleted first. diff --git a/docs/中文/快速开始/游戏服水平伸缩.md b/docs/中文/快速开始/游戏服水平伸缩.md index 52097c5..7599527 100644 --- a/docs/中文/快速开始/游戏服水平伸缩.md +++ b/docs/中文/快速开始/游戏服水平伸缩.md @@ -4,7 +4,7 @@ OKG提供游戏服状态设置的能力,您可以手动/自动(服务质量功能)地设置游戏服的运维状态或删除优先级。当缩容时,GameServerSet负载会根据游戏服的状态进行缩容选择,缩容规则如下: -1)根据游戏服的opsState缩容。按顺序依次缩容opsState为`WaitToBeDeleted`、`None`、`Maintaining`的游戏服 +1)根据游戏服的opsState缩容。按顺序依次缩容opsState为`WaitToBeDeleted`、`None`、`Allocated`、`Maintaining`的游戏服 2)当opsState相同时,按照DeletionPriority(删除优先级)缩容,优先删除DeletionPriority大的游戏服 diff --git a/pkg/util/gameserver.go b/pkg/util/gameserver.go index 9011590..8d3ac84 100644 --- a/pkg/util/gameserver.go +++ b/pkg/util/gameserver.go @@ -69,8 +69,10 @@ func opsStateDeletePrority(opsState string) int { return 1 case string(gameKruiseV1alpha1.None): return 0 - case string(gameKruiseV1alpha1.Maintaining): + case string(gameKruiseV1alpha1.Allocated): return -1 + case string(gameKruiseV1alpha1.Maintaining): + return -2 } return 0 } diff --git a/pkg/util/gameserver_test.go b/pkg/util/gameserver_test.go index ca15c78..e6b00c8 100644 --- a/pkg/util/gameserver_test.go +++ b/pkg/util/gameserver_test.go @@ -94,6 +94,47 @@ func TestDeleteSequenceGs(t *testing.T) { }, after: []int{2, 0, 3, 1}, }, + { + before: []corev1.Pod{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "xxx-0", + Labels: map[string]string{ + gameKruiseV1alpha1.GameServerOpsStateKey: string(gameKruiseV1alpha1.Allocated), + gameKruiseV1alpha1.GameServerDeletePriorityKey: "0", + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "xxx-1", + Labels: map[string]string{ + gameKruiseV1alpha1.GameServerOpsStateKey: string(gameKruiseV1alpha1.Maintaining), + gameKruiseV1alpha1.GameServerDeletePriorityKey: "0", + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "xxx-2", + Labels: map[string]string{ + gameKruiseV1alpha1.GameServerOpsStateKey: string(gameKruiseV1alpha1.WaitToDelete), + gameKruiseV1alpha1.GameServerDeletePriorityKey: "0", + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "xxx-3", + Labels: map[string]string{ + gameKruiseV1alpha1.GameServerOpsStateKey: string(gameKruiseV1alpha1.None), + gameKruiseV1alpha1.GameServerDeletePriorityKey: "0", + }, + }, + }, + }, + after: []int{2, 3, 0, 1}, + }, } for _, test := range tests {