From 92475c1451decebabe55108580c0b10105ea28a8 Mon Sep 17 00:00:00 2001 From: ChrisLiu <70144550+chrisliu1995@users.noreply.github.com> Date: Fri, 16 Aug 2024 10:44:48 +0800 Subject: [PATCH] enhance: labels from gs can be synced to pod (#160) Signed-off-by: ChrisLiu --- pkg/controllers/gameserver/gameserver_manager.go | 11 +++++++++++ pkg/controllers/gameserver/gameserver_manager_test.go | 2 ++ 2 files changed, 13 insertions(+) diff --git a/pkg/controllers/gameserver/gameserver_manager.go b/pkg/controllers/gameserver/gameserver_manager.go index 3e0bfe00..e10542c7 100644 --- a/pkg/controllers/gameserver/gameserver_manager.go +++ b/pkg/controllers/gameserver/gameserver_manager.go @@ -196,6 +196,17 @@ func (manager GameServerManager) SyncGsToPod() error { } } + // sync labels from gs to pod + for gsKey, gsValue := range gs.GetLabels() { + if util.IsHasPrefixGsSyncToPod(gsKey) { + podValue, exist := pod.GetLabels()[gsKey] + if exist && (podValue == gsValue) { + continue + } + newLabels[gsKey] = gsValue + } + } + // sync pod containers when the containers(images) in GameServer are different from that in pod. containers := manager.syncPodContainers(gs.Spec.Containers, pod.DeepCopy().Spec.Containers) diff --git a/pkg/controllers/gameserver/gameserver_manager_test.go b/pkg/controllers/gameserver/gameserver_manager_test.go index 9ed3312c..80974d55 100644 --- a/pkg/controllers/gameserver/gameserver_manager_test.go +++ b/pkg/controllers/gameserver/gameserver_manager_test.go @@ -464,6 +464,7 @@ func TestSyncGsToPod(t *testing.T) { Name: "xxx-0", Labels: map[string]string{ gameKruiseV1alpha1.GameServerOwnerGssKey: "xxx", + "gs-sync/pre-deleting": "false", }, Annotations: map[string]string{ "meaningless-key": "meaningless-value", @@ -488,6 +489,7 @@ func TestSyncGsToPod(t *testing.T) { gameKruiseV1alpha1.GameServerDeletePriorityKey: dp.String(), gameKruiseV1alpha1.GameServerUpdatePriorityKey: up.String(), gameKruiseV1alpha1.GameServerStateKey: string(gameKruiseV1alpha1.Creating), + "gs-sync/pre-deleting": "false", }, Annotations: map[string]string{ "gs-sync/match-id": "xxx-xxx-xx2",