feat: add new opsState named Allocated (#89)

Signed-off-by: ChrisLiu <chrisliu1995@163.com>
This commit is contained in:
ChrisLiu 2023-07-28 14:49:20 +08:00 committed by GitHub
parent 6f89f6e637
commit 1b05801484
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 3 deletions

View File

@ -61,6 +61,7 @@ const (
Maintaining OpsState = "Maintaining"
WaitToDelete OpsState = "WaitToBeDeleted"
None OpsState = "None"
Allocated OpsState = "Allocated"
)
type ServiceQuality struct {

View File

@ -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.

View File

@ -4,7 +4,7 @@
OKG提供游戏服状态设置的能力您可以手动/自动(服务质量功能)地设置游戏服的运维状态或删除优先级。当缩容时GameServerSet负载会根据游戏服的状态进行缩容选择缩容规则如下
1根据游戏服的opsState缩容。按顺序依次缩容opsState为`WaitToBeDeleted`、`None`、`Maintaining`的游戏服
1根据游戏服的opsState缩容。按顺序依次缩容opsState为`WaitToBeDeleted`、`None`、`Allocated`、`Maintaining`的游戏服
2当opsState相同时按照DeletionPriority(删除优先级)缩容优先删除DeletionPriority大的游戏服

View File

@ -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
}

View File

@ -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 {