enhance: labels from gs can be synced to pod (#160)

Signed-off-by: ChrisLiu <chrisliu1995@163.com>
This commit is contained in:
ChrisLiu 2024-08-16 10:44:48 +08:00 committed by GitHub
parent 26fcaf7889
commit 92475c1451
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -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. // 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) containers := manager.syncPodContainers(gs.Spec.Containers, pod.DeepCopy().Spec.Containers)

View File

@ -464,6 +464,7 @@ func TestSyncGsToPod(t *testing.T) {
Name: "xxx-0", Name: "xxx-0",
Labels: map[string]string{ Labels: map[string]string{
gameKruiseV1alpha1.GameServerOwnerGssKey: "xxx", gameKruiseV1alpha1.GameServerOwnerGssKey: "xxx",
"gs-sync/pre-deleting": "false",
}, },
Annotations: map[string]string{ Annotations: map[string]string{
"meaningless-key": "meaningless-value", "meaningless-key": "meaningless-value",
@ -488,6 +489,7 @@ func TestSyncGsToPod(t *testing.T) {
gameKruiseV1alpha1.GameServerDeletePriorityKey: dp.String(), gameKruiseV1alpha1.GameServerDeletePriorityKey: dp.String(),
gameKruiseV1alpha1.GameServerUpdatePriorityKey: up.String(), gameKruiseV1alpha1.GameServerUpdatePriorityKey: up.String(),
gameKruiseV1alpha1.GameServerStateKey: string(gameKruiseV1alpha1.Creating), gameKruiseV1alpha1.GameServerStateKey: string(gameKruiseV1alpha1.Creating),
"gs-sync/pre-deleting": "false",
}, },
Annotations: map[string]string{ Annotations: map[string]string{
"gs-sync/match-id": "xxx-xxx-xx2", "gs-sync/match-id": "xxx-xxx-xx2",