Skip to content

Commit

Permalink
Simple Game Server: Add \n to Counters and Lists Response (#3589)
Browse files Browse the repository at this point in the history
* Simple Game Server: Add \n to Counters and Lists Response

* gofmt

* Changes in functions

* fine tuning

* missing quotes

* Change in listContains and getListValues

* update main.go and gameserver_test.go files

* NO Values for getListValues

* review change

* NO Values when list empty

* update list contains

* modify listContains and getListValues

* Rename success with FOUND

* Review changes

* bump simple-game-server image

* bump simple-game-server image outside example/simple-game-server

* adjust expected value

* update response for counters and lists in fleet_test.go

* modify listContains

* bump simple-game-server
  • Loading branch information
Kalaiselvi84 authored Jan 30, 2024
1 parent f445b49 commit 2477589
Show file tree
Hide file tree
Showing 24 changed files with 95 additions and 79 deletions.
2 changes: 1 addition & 1 deletion build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ KIND_PROFILE ?= agones
KIND_CONTAINER_NAME=$(KIND_PROFILE)-control-plane

# Game Server image to use while doing end-to-end tests
GS_TEST_IMAGE ?= us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25
GS_TEST_IMAGE ?= us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27

# Enable all alpha feature gates. Keep in sync with `false` (alpha) entries in pkg/util/runtime/features.go:featureDefaults
ALPHA_FEATURE_GATES ?= "PlayerAllocationFilter=true&PlayerTracking=true&CountsAndLists=true&DisableResyncOnSDKServer=true&Example=true"
Expand Down
2 changes: 1 addition & 1 deletion examples/crd-client/create-gs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ spec:
imagePullPolicy: Always
env:
- name: GAMESERVER_IMAGE
value: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25
value: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27
restartPolicy: Never
2 changes: 1 addition & 1 deletion examples/fleet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ spec:
spec:
containers:
- name: simple-game-server
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27
2 changes: 1 addition & 1 deletion examples/gameserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ spec:
spec:
containers:
- name: simple-game-server
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27
imagePullPolicy: Always
# nodeSelector is a label that can be used to tell Kubernetes which host
# OS to use. For Windows game servers uncomment the nodeSelector
Expand Down
4 changes: 2 additions & 2 deletions examples/simple-game-server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ WITH_ARM64 ?= 1
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
project_path := $(dir $(mkfile_path))
ifeq ($(REPOSITORY),)
server_tag := simple-game-server:0.25
server_tag := simple-game-server:0.27
else
server_tag := $(REPOSITORY)/simple-game-server:0.25
server_tag := $(REPOSITORY)/simple-game-server:0.27
endif

ifeq ($(WITH_WINDOWS), 1)
Expand Down
12 changes: 6 additions & 6 deletions examples/simple-game-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ There are some text commands you can send the server to affect its behavior:
| "GET_COUNTER_CAPACITY" | Returns the Capacity of the given Counter |
| "SET_COUNTER_CAPACITY" | Sets the Capacity of the given Counter to the given amount |
| "GET_LIST_CAPACITY" | Returns the Capacity of the given List |
| "SET_LIST_CAPACITY | Returns if the List was set to a new Capacity successfully (true) or not (false) |
| "LIST_CONTAINS | Returns true if the given value is in the given List, false otherwise |
| "GET_LIST_LENGTH | Returns the length (number of values) of the given List as a string |
| "GET_LIST_VALUES | Return the values in the given List as a comma delineated string |
| "APPEND_LIST_VALUE | Returns if the given value was successfuly added to the List (true) or not (false) |
| "DELETE_LIST_VALUE | Rreturns if the given value was successfuly deleted from the List (true) or not (false) |
| "SET_LIST_CAPACITY" | Returns if the List was set to a new Capacity successfully (true) or not (false) |
| "LIST_CONTAINS" | Returns true if the given value is in the given List, false otherwise |
| "GET_LIST_LENGTH" | Returns the length (number of values) of the given List as a string |
| "GET_LIST_VALUES" | Return the values in the given List as a comma delineated string |
| "APPEND_LIST_VALUE" | Returns if the given value was successfuly added to the List (true) or not (false) |
| "DELETE_LIST_VALUE" | Rreturns if the given value was successfuly deleted from the List (true) or not (false) |

## Configuration

Expand Down
2 changes: 1 addition & 1 deletion examples/simple-game-server/dev-gameserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ spec:
spec:
containers:
- name: simple-game-server
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27
2 changes: 1 addition & 1 deletion examples/simple-game-server/fleet-distributed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
spec:
containers:
- name: simple-game-server
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27
resources:
requests:
memory: 64Mi
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-game-server/fleet-tcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec:
spec:
containers:
- name: simple-game-server
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27
env:
# Disables the UDP listener (Enabled by default)
- name: UDP
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-game-server/fleet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
spec:
containers:
- name: simple-game-server
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27
resources:
requests:
memory: 64Mi
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-game-server/gameserver-passthrough.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
spec:
containers:
- name: simple-game-server
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27
env:
- name: PASSTHROUGH
value: 'TRUE'
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-game-server/gameserver-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
spec:
containers:
- name: simple-game-server
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27
resources:
requests:
memory: 64Mi
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-game-server/gameserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
spec:
containers:
- name: simple-game-server
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27
resources:
requests:
memory: 64Mi
Expand Down
44 changes: 30 additions & 14 deletions examples/simple-game-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,9 @@ func getCounterCount(s *sdk.SDK, counterName string) (string, error) {
count, err := s.Alpha().GetCounterCount(counterName)
if err != nil {
log.Printf("Error getting Counter %s Count: %s", counterName, err)
return strconv.FormatInt(count, 10), err
}
return strconv.FormatInt(count, 10), err
return "COUNTER: " + strconv.FormatInt(count, 10) + "\n", nil
}

// incrementCounter returns the if the Counter Count was incremented successfully (true) or not (false)
Expand All @@ -701,8 +702,9 @@ func incrementCounter(s *sdk.SDK, counterName string, amount string) (string, er
ok, err := s.Alpha().IncrementCounter(counterName, amountInt)
if err != nil {
log.Printf("Error incrementing Counter %s Count by amount %d: %s", counterName, amountInt, err)
return strconv.FormatBool(ok), err
}
return strconv.FormatBool(ok), err
return "SUCCESS: " + strconv.FormatBool(ok) + "\n", nil
}

// decrementCounter returns the if the Counter Count was decremented successfully (true) or not (false)
Expand All @@ -715,8 +717,9 @@ func decrementCounter(s *sdk.SDK, counterName string, amount string) (string, er
ok, err := s.Alpha().DecrementCounter(counterName, amountInt)
if err != nil {
log.Printf("Error decrementing Counter %s Count by amount %d: %s", counterName, amountInt, err)
return strconv.FormatBool(ok), err
}
return strconv.FormatBool(ok), err
return "SUCCESS: " + strconv.FormatBool(ok) + "\n", nil
}

// setCounterCount returns the if the Counter was set to a new Count successfully (true) or not (false)
Expand All @@ -729,8 +732,9 @@ func setCounterCount(s *sdk.SDK, counterName string, amount string) (string, err
ok, err := s.Alpha().SetCounterCount(counterName, amountInt)
if err != nil {
log.Printf("Error setting Counter %s Count by amount %d: %s", counterName, amountInt, err)
return strconv.FormatBool(ok), err
}
return strconv.FormatBool(ok), err
return "SUCCESS: " + strconv.FormatBool(ok) + "\n", nil
}

// getCounterCapacity returns the Capacity of the given Counter as a string
Expand All @@ -739,8 +743,9 @@ func getCounterCapacity(s *sdk.SDK, counterName string) (string, error) {
count, err := s.Alpha().GetCounterCapacity(counterName)
if err != nil {
log.Printf("Error getting Counter %s Capacity: %s", counterName, err)
return strconv.FormatInt(count, 10), err
}
return strconv.FormatInt(count, 10), err
return "CAPACITY: " + strconv.FormatInt(count, 10) + "\n", nil
}

// setCounterCapacity returns the if the Counter was set to a new Capacity successfully (true) or not (false)
Expand All @@ -753,8 +758,9 @@ func setCounterCapacity(s *sdk.SDK, counterName string, amount string) (string,
ok, err := s.Alpha().SetCounterCapacity(counterName, amountInt)
if err != nil {
log.Printf("Error setting Counter %s Capacity to amount %d: %s", counterName, amountInt, err)
return strconv.FormatBool(ok), err
}
return strconv.FormatBool(ok), err
return "SUCCESS: " + strconv.FormatBool(ok) + "\n", nil
}

// getListCapacity returns the Capacity of the given List as a string
Expand All @@ -763,8 +769,9 @@ func getListCapacity(s *sdk.SDK, listName string) (string, error) {
capacity, err := s.Alpha().GetListCapacity(listName)
if err != nil {
log.Printf("Error getting List %s Capacity: %s", listName, err)
return strconv.FormatInt(capacity, 10), err
}
return strconv.FormatInt(capacity, 10), err
return "CAPACITY: " + strconv.FormatInt(capacity, 10) + "\n", nil
}

// setListCapacity returns if the List was set to a new Capacity successfully (true) or not (false)
Expand All @@ -777,8 +784,9 @@ func setListCapacity(s *sdk.SDK, listName string, amount string) (string, error)
ok, err := s.Alpha().SetListCapacity(listName, amountInt)
if err != nil {
log.Printf("Error setting List %s Capacity to amount %d: %s", listName, amountInt, err)
return strconv.FormatBool(ok), err
}
return strconv.FormatBool(ok), err
return "SUCCESS: " + strconv.FormatBool(ok) + "\n", nil
}

// listContains returns true if the given value is in the given List, false otherwise
Expand All @@ -787,8 +795,9 @@ func listContains(s *sdk.SDK, listName string, value string) (string, error) {
ok, err := s.Alpha().ListContains(listName, value)
if err != nil {
log.Printf("Error getting List %s contains value %s: %s", listName, value, err)
}
return strconv.FormatBool(ok), err
return strconv.FormatBool(ok), err
}
return "FOUND: " + strconv.FormatBool(ok) + "\n", nil
}

// getListLength returns the length (number of values) of the given List as a string
Expand All @@ -797,8 +806,9 @@ func getListLength(s *sdk.SDK, listName string) (string, error) {
length, err := s.Alpha().GetListLength(listName)
if err != nil {
log.Printf("Error getting List %s length: %s", listName, err)
return strconv.Itoa(length), err
}
return strconv.Itoa(length), err
return "LENGTH: " + strconv.Itoa(length) + "\n", nil
}

// getListValues return the values in the given List as a comma delineated string
Expand All @@ -807,8 +817,12 @@ func getListValues(s *sdk.SDK, listName string) (string, error) {
values, err := s.Alpha().GetListValues(listName)
if err != nil {
log.Printf("Error getting List %s values: %s", listName, err)
return "INVALID LIST NAME", err
}
return strings.Join(values, ",") + "\n", err
if len(values) > 0 {
return "VALUES: " + strings.Join(values, ",") + "\n", nil
}
return "VALUES: <none>\n", err
}

// appendListValue returns if the given value was successfuly added to the List (true) or not (false)
Expand All @@ -817,8 +831,9 @@ func appendListValue(s *sdk.SDK, listName string, value string) (string, error)
ok, err := s.Alpha().AppendListValue(listName, value)
if err != nil {
log.Printf("Error appending Value %s to List %s: %s", value, listName, err)
return strconv.FormatBool(ok), err
}
return strconv.FormatBool(ok), err
return "SUCCESS: " + strconv.FormatBool(ok) + "\n", nil
}

// deleteListValue returns if the given value was successfuly deleted from the List (true) or not (false)
Expand All @@ -827,8 +842,9 @@ func deleteListValue(s *sdk.SDK, listName string, value string) (string, error)
ok, err := s.Alpha().DeleteListValue(listName, value)
if err != nil {
log.Printf("Error deleting Value %s to List %s: %s", value, listName, err)
return strconv.FormatBool(ok), err
}
return strconv.FormatBool(ok), err
return "SUCCESS: " + strconv.FormatBool(ok) + "\n", nil
}

// doHealth sends the regular Health Pings
Expand Down
2 changes: 1 addition & 1 deletion install/helm/agones/templates/tests/test-runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
imagePullPolicy: Always
env:
- name: GAMESERVER_IMAGE
value: "us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25"
value: "us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27"
- name: IS_HELM_TEST
value: "true"
- name: GAMESERVERS_NAMESPACE
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/webhooks/webhooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestWebHookFleetValidationHandler(t *testing.T) {
"template": {
"spec": {
"containers": [{
"image": "us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25",
"image": "us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27",
"name": false
}]
}
Expand Down
2 changes: 1 addition & 1 deletion site/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ dev_eks_example_cluster_version = "1.28"
dev_minikube_example_cluster_version = "1.27.6"

# example tag
example_image_tag = "us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25"
example_image_tag = "us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27"

# Enable syntax highlighting and copy buttons on code blocks with Prism
prism_syntax_highlighting = true
Expand Down
2 changes: 1 addition & 1 deletion site/content/en/docs/Guides/fleet-updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ spec:
spec:
containers:
- name: simple-game-server
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27
```

See the [Fleet reference]({{% relref "../Reference/fleet.md" %}}) for more details.
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/fleet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1659,13 +1659,13 @@ func TestFleetAggregatedCounterStatus(t *testing.T) {
msg := fmt.Sprintf("SET_COUNTER_CAPACITY games %d", capacity)
reply, err := framework.SendGameServerUDP(t, &gs, msg)
require.NoError(t, err)
assert.Equal(t, "true", reply)
assert.Equal(t, "SUCCESS: true\n", reply)

totalCount += count
msg = fmt.Sprintf("SET_COUNTER_COUNT games %d", count)
reply, err = framework.SendGameServerUDP(t, &gs, msg)
require.NoError(t, err)
assert.Equal(t, "true", reply)
assert.Equal(t, "SUCCESS: true\n", reply)

if gs.Status.State == agonesv1.GameServerStateAllocated {
allocatedCapacity += capacity
Expand Down Expand Up @@ -1742,15 +1742,15 @@ func TestFleetAggregatedListStatus(t *testing.T) {
msg := fmt.Sprintf("SET_LIST_CAPACITY gamers %d", capacity)
reply, err := framework.SendGameServerUDP(t, &gs, msg)
require.NoError(t, err)
assert.Equal(t, "true", reply)
assert.Equal(t, "SUCCESS: true\n", reply)

totalCount += count
// Each list starts with a count of 2 (Values: []string{"gamer0", "gamer1"})
for i := 2; i < count; i++ {
msg = fmt.Sprintf("APPEND_LIST_VALUE gamers gamer%d", i)
reply, err = framework.SendGameServerUDP(t, &gs, msg)
require.NoError(t, err)
assert.Equal(t, "true", reply)
assert.Equal(t, "SUCCESS: true\n", reply)
}

if gs.Status.State == agonesv1.GameServerStateAllocated {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func NewFromFlags() (*Framework, error) {
}

viper.SetDefault(kubeconfigFlag, filepath.Join(usr.HomeDir, ".kube", "config"))
viper.SetDefault(gsimageFlag, "us-docker.pkg.dev/agones-images/examples/simple-game-server:0.25")
viper.SetDefault(gsimageFlag, "us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27")
viper.SetDefault(pullSecretFlag, "")
viper.SetDefault(stressTestLevelFlag, 0)
viper.SetDefault(perfOutputDirFlag, "")
Expand Down
Loading

0 comments on commit 2477589

Please sign in to comment.