From 42b1a9289df3c0f81960d56a9819a695303f0659 Mon Sep 17 00:00:00 2001 From: Kalaiselvim <117940852+Kalaiselvi84@users.noreply.github.com> Date: Fri, 1 Mar 2024 01:44:29 +0000 Subject: [PATCH] Local SDK: Counters and Lists (#3660) * local SDK: counter and lists * Review changes * Review changes --- pkg/sdkserver/localsdk.go | 34 ++++++++++++------- .../en/docs/Guides/Client SDKs/local.md | 2 ++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/pkg/sdkserver/localsdk.go b/pkg/sdkserver/localsdk.go index 6f3f527f24..4f5e8ce6ac 100644 --- a/pkg/sdkserver/localsdk.go +++ b/pkg/sdkserver/localsdk.go @@ -25,18 +25,19 @@ import ( "sync" "time" - agonesv1 "agones.dev/agones/pkg/apis/agones/v1" - "agones.dev/agones/pkg/sdk" - "agones.dev/agones/pkg/sdk/alpha" - "agones.dev/agones/pkg/sdk/beta" - "agones.dev/agones/pkg/util/apiserver" - "agones.dev/agones/pkg/util/runtime" "github.com/fsnotify/fsnotify" "github.com/mennanov/fmutils" "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/protobuf/proto" "k8s.io/apimachinery/pkg/util/yaml" + + agonesv1 "agones.dev/agones/pkg/apis/agones/v1" + "agones.dev/agones/pkg/sdk" + "agones.dev/agones/pkg/sdk/alpha" + "agones.dev/agones/pkg/sdk/beta" + "agones.dev/agones/pkg/util/apiserver" + "agones.dev/agones/pkg/util/runtime" ) var ( @@ -46,7 +47,7 @@ var ( ) func defaultGs() *sdk.GameServer { - return &sdk.GameServer{ + gs := &sdk.GameServer{ ObjectMeta: &sdk.GameServer_ObjectMeta{ Name: "local", Namespace: "default", @@ -71,6 +72,17 @@ func defaultGs() *sdk.GameServer { Ports: []*sdk.GameServer_Status_Port{{Name: "default", Port: 7777}}, }, } + + if runtime.FeatureEnabled(runtime.FeatureCountsAndLists) { + gs.Status.Counters = map[string]*sdk.GameServer_Status_CounterStatus{ + "rooms": {Count: 1, Capacity: 10}, + } + gs.Status.Lists = map[string]*sdk.GameServer_Status_ListStatus{ + "players": {Values: []string{"test0", "test1", "test2"}, Capacity: 100}, + } + } + + return gs } // LocalSDKServer type is the SDKServer implementation for when the sidecar @@ -144,15 +156,13 @@ func NewLocalSDKServer(filePath string, testSdkName string) (*LocalSDKServer, er if runtime.FeatureEnabled(runtime.FeaturePlayerTracking) && l.gs.Status.Players == nil { l.gs.Status.Players = &sdk.GameServer_Status_PlayerStatus{} } + if runtime.FeatureEnabled(runtime.FeatureCountsAndLists) { - // Adding test Counter and List for the conformance tests (not nil for LocalSDKServer tests) if l.gs.Status.Counters == nil { - l.gs.Status.Counters = map[string]*sdk.GameServer_Status_CounterStatus{ - "rooms": {Count: 1, Capacity: 10}} + l.gs.Status.Counters = make(map[string]*sdk.GameServer_Status_CounterStatus) } if l.gs.Status.Lists == nil { - l.gs.Status.Lists = map[string]*sdk.GameServer_Status_ListStatus{ - "players": {Values: []string{"test0", "test1", "test2"}, Capacity: 100}} + l.gs.Status.Lists = make(map[string]*sdk.GameServer_Status_ListStatus) } } diff --git a/site/content/en/docs/Guides/Client SDKs/local.md b/site/content/en/docs/Guides/Client SDKs/local.md index be524ccbd4..dc92020cdc 100644 --- a/site/content/en/docs/Guides/Client SDKs/local.md +++ b/site/content/en/docs/Guides/Client SDKs/local.md @@ -85,6 +85,8 @@ this will be picked up by the local server, and will change the current active c events for `WatchGameServer()`. This is a useful way of testing functionality, such as changes of state from `Ready` to `Allocated` in your game server code. +It's important to note that during local development, only specific parts of the GameServer configuration can be modified through SDK calls. For instance, `counters` and `lists` should be placed within the `gameserver.status` section of the configuration file. By making this change, the relevant parts of the configuration are properly exposed and can be accessed through the SDK calls. + {{< alert title="Note" color="info">}} File modification events can fire more than one for each save (for a variety of reasons), but it's best practice to ensure handlers that implement `WatchGameServer()` be idempotent regardless, as repeats can