From 65b652027f7446a685a74bfcdddd8a158d87fa75 Mon Sep 17 00:00:00 2001 From: ChrisLiu Date: Tue, 8 Aug 2023 21:15:52 +0800 Subject: [PATCH 1/2] feat: add new field ServiceName for GameServerSet Signed-off-by: ChrisLiu --- apis/v1alpha1/gameserverset_types.go | 1 + config/crd/bases/game.kruise.io_gameserversets.yaml | 2 ++ pkg/controllers/gameserverset/gameserverset_controller.go | 7 +++++++ pkg/util/gameserver.go | 2 -- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apis/v1alpha1/gameserverset_types.go b/apis/v1alpha1/gameserverset_types.go index dcd6177f..379c2f93 100644 --- a/apis/v1alpha1/gameserverset_types.go +++ b/apis/v1alpha1/gameserverset_types.go @@ -47,6 +47,7 @@ type GameServerSetSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file GameServerTemplate GameServerTemplate `json:"gameServerTemplate,omitempty"` + ServiceName string `json:"serviceName,omitempty"` ReserveGameServerIds []int `json:"reserveGameServerIds,omitempty"` ServiceQualities []ServiceQuality `json:"serviceQualities,omitempty"` UpdateStrategy UpdateStrategy `json:"updateStrategy,omitempty"` diff --git a/config/crd/bases/game.kruise.io_gameserversets.yaml b/config/crd/bases/game.kruise.io_gameserversets.yaml index ba45f775..12d1cce5 100644 --- a/config/crd/bases/game.kruise.io_gameserversets.yaml +++ b/config/crd/bases/game.kruise.io_gameserversets.yaml @@ -422,6 +422,8 @@ spec: strategy. Default is GeneralScaleDownStrategyType type: string type: object + serviceName: + type: string serviceQualities: items: properties: diff --git a/pkg/controllers/gameserverset/gameserverset_controller.go b/pkg/controllers/gameserverset/gameserverset_controller.go index b95d8e42..26a12c1f 100644 --- a/pkg/controllers/gameserverset/gameserverset_controller.go +++ b/pkg/controllers/gameserverset/gameserverset_controller.go @@ -300,6 +300,13 @@ func (r *GameServerSetReconciler) initAsts(gss *gamekruiseiov1alpha1.GameServerS asts.Spec.Replicas = gss.Spec.Replicas asts.Spec.ReserveOrdinals = gss.Spec.ReserveGameServerIds + // set ServiceName + asts.Spec.ServiceName = gss.Spec.ServiceName + if asts.Spec.ServiceName == "" { + // default: GameServerSet name + asts.Spec.ServiceName = gss.Name + } + asts = util.GetNewAstsFromGss(gss.DeepCopy(), asts) return r.Client.Create(context.Background(), asts) diff --git a/pkg/util/gameserver.go b/pkg/util/gameserver.go index 0d580a36..6c24ecfc 100644 --- a/pkg/util/gameserver.go +++ b/pkg/util/gameserver.go @@ -104,8 +104,6 @@ func GetIndexListFromGsList(gsList []gameKruiseV1alpha1.GameServer) []int { func GetNewAstsFromGss(gss *gameKruiseV1alpha1.GameServerSet, asts *kruiseV1beta1.StatefulSet) *kruiseV1beta1.StatefulSet { // default: set ParallelPodManagement asts.Spec.PodManagementPolicy = apps.ParallelPodManagement - // default: set ServiceName as GameServerSet name - asts.Spec.ServiceName = gss.Name // set pod labels podLabels := gss.Spec.GameServerTemplate.GetLabels() From 02b9a94be3bfecb3a157bd7869d763e6cf1dc9bc Mon Sep 17 00:00:00 2001 From: ChrisLiu Date: Tue, 8 Aug 2023 21:21:42 +0800 Subject: [PATCH 2/2] fix log for kill gs Signed-off-by: ChrisLiu --- pkg/controllers/gameserverset/gameserverset_manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controllers/gameserverset/gameserverset_manager.go b/pkg/controllers/gameserverset/gameserverset_manager.go index f2ee5f87..7a6e17a3 100644 --- a/pkg/controllers/gameserverset/gameserverset_manager.go +++ b/pkg/controllers/gameserverset/gameserverset_manager.go @@ -94,7 +94,7 @@ func (manager *GameServerSetManager) GetReplicasAfterKilling() *int32 { } } - klog.Infof("%d GameServers need to be killed", toKill) + klog.Infof("GameServerSet %s/%s will kill %d GameServers", gss.GetNamespace(), gss.GetName(), toKill) return pointer.Int32(*gss.Spec.Replicas - int32(toKill)) }