Skip to content

Commit

Permalink
Delete List Value(s) on Game Server Allocation (#4054)
Browse files Browse the repository at this point in the history
* Adds DeleteValues as a ListAction during allocation

* Generated Files

* Adds tests

* Adds DeleteValues documentation

* Updates tabs to spaces per protobuf style guide

* Generate Rust file

* Adds unit test for DeleteListValues
igooch authored Dec 13, 2024
1 parent ccca32a commit 3c5b7df
Showing 18 changed files with 269 additions and 78 deletions.
3 changes: 3 additions & 0 deletions examples/gameserverallocation.yaml
Original file line number Diff line number Diff line change
@@ -116,3 +116,6 @@ spec:
- x7un
- 8inz
capacity: 40 # Updates the maximum capacity of the Counter to this number. Min 0, Max 1000.
deleteValues: # removes values from a List's Valules array. Any nonexistant values are ignored.
- alice
- bob
11 changes: 11 additions & 0 deletions pkg/allocation/converters/converter.go
Original file line number Diff line number Diff line change
@@ -615,6 +615,12 @@ func convertAllocationListsToGSAListActions(in map[string]*pb.ListAction) map[st
copy(copyValues, addValues)
la.AddValues = copyValues
}
if v.DeleteValues != nil {
deleteValues := v.GetDeleteValues()
copyValues := make([]string, len(deleteValues))
copy(copyValues, deleteValues)
la.DeleteValues = copyValues
}
if v.Capacity != nil {
capacity := v.Capacity.GetValue()
la.Capacity = &capacity
@@ -639,6 +645,11 @@ func convertGSAListActionsToAllocationLists(in map[string]allocationv1.ListActio
copy(copyValues, v.AddValues)
la.AddValues = copyValues
}
if v.DeleteValues != nil {
copyValues := make([]string, len(v.DeleteValues))
copy(copyValues, v.DeleteValues)
la.DeleteValues = copyValues
}
if v.Capacity != nil {
la.Capacity = wrapperspb.Int64(*v.Capacity)
}
16 changes: 12 additions & 4 deletions pkg/allocation/converters/converter_test.go
Original file line number Diff line number Diff line change
@@ -135,8 +135,9 @@ func TestConvertAllocationRequestToGameServerAllocation(t *testing.T) {
},
Lists: map[string]*pb.ListAction{
"p": {
AddValues: []string{"foo", "bar", "baz"},
Capacity: wrapperspb.Int64(10),
AddValues: []string{"foo", "bar", "baz"},
Capacity: wrapperspb.Int64(10),
DeleteValues: []string{"alice", "bob", "cat"},
},
},
Scheduling: pb.AllocationRequest_Packed,
@@ -217,8 +218,9 @@ func TestConvertAllocationRequestToGameServerAllocation(t *testing.T) {
},
Lists: map[string]allocationv1.ListAction{
"p": {
AddValues: []string{"foo", "bar", "baz"},
Capacity: &ten,
AddValues: []string{"foo", "bar", "baz"},
Capacity: &ten,
DeleteValues: []string{"alice", "bob", "cat"},
},
},
Selectors: []allocationv1.GameServerSelector{
@@ -742,6 +744,9 @@ func TestConvertGSAToAllocationRequest(t *testing.T) {
"d": {
Capacity: &two,
},
"c": {
DeleteValues: []string{"good", "bye"},
},
},
Scheduling: apis.Distributed,
},
@@ -821,6 +826,9 @@ func TestConvertGSAToAllocationRequest(t *testing.T) {
"d": {
Capacity: wrapperspb.Int64(two),
},
"c": {
DeleteValues: []string{"good", "bye"},
},
},
},
},
61 changes: 36 additions & 25 deletions pkg/allocation/go/allocation.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion pkg/allocation/go/allocation.swagger.json
Original file line number Diff line number Diff line change
@@ -351,9 +351,15 @@
"capacity": {
"type": "string",
"format": "int64"
},
"deleteValues": {
"type": "array",
"items": {
"type": "string"
}
}
},
"description": "ListAction is an optional action that can be performed on a List at allocation.\nAddValues: Append values to a List's Values array (optional). Any duplicate values will be ignored.\nCapacity: Update the maximum capacity of the Counter to this number (optional). Min 0, Max 1000."
"description": "ListAction is an optional action that can be performed on a List at allocation.\nAddValues: Append values to a List's Values array (optional). Any duplicate values will be ignored.\nCapacity: Update the maximum capacity of the Counter to this number (optional). Min 0, Max 1000.\nDeleteValues: Remove values from a List's Values array (optional). Any nonexistant values will be ignored."
},
"allocationListSelector": {
"type": "object",
31 changes: 31 additions & 0 deletions pkg/apis/agones/v1/gameserver.go
Original file line number Diff line number Diff line change
@@ -1026,6 +1026,37 @@ func (gs *GameServer) AppendListValues(name string, values []string) error {
return errors.Errorf("unable to AppendListValues: Name %s, Values %s. List not found in GameServer %s", name, values, gs.ObjectMeta.GetName())
}

// DeleteListValues removes values from the ListStatus Values list. Values in the DeleteListValues
// list that are not in the ListStatus Values list are ignored.
func (gs *GameServer) DeleteListValues(name string, values []string) error {
if values == nil {
return errors.Errorf("unable to DeleteListValues: Name %s, Values %s. Values must not be nil", name, values)
}
if list, ok := gs.Status.Lists[name]; ok {
deleteValuesMap := make(map[string]bool)
for _, value := range values {
deleteValuesMap[value] = true
}
newList := deleteValues(list.Values, deleteValuesMap)
list.Values = newList
gs.Status.Lists[name] = list
return nil
}
return errors.Errorf("unable to DeleteListValues: Name %s, Values %s. List not found in GameServer %s", name, values, gs.ObjectMeta.GetName())
}

// deleteValues returns a new list with all the values in valuesList that are not keys in deleteValuesMap.
func deleteValues(valuesList []string, deleteValuesMap map[string]bool) []string {
newValuesList := []string{}
for _, value := range valuesList {
if _, ok := deleteValuesMap[value]; ok {
continue
}
newValuesList = append(newValuesList, value)
}
return newValuesList
}

// truncateList truncates the list to the given capacity
func truncateList(capacity int64, list []string) []string {
if list == nil || len(list) <= int(capacity) {
57 changes: 57 additions & 0 deletions pkg/apis/agones/v1/gameserver_test.go
Original file line number Diff line number Diff line change
@@ -2223,6 +2223,63 @@ func TestGameServerAppendListValues(t *testing.T) {
}
}

func TestGameServerDeleteListValues(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
gs GameServer
name string
want ListStatus
values []string
wantErr bool
}{
"list not in game server no-op and error": {
gs: GameServer{Status: GameServerStatus{
Lists: map[string]ListStatus{
"foos": {
Values: []string{"foo", "bar", "bax"},
Capacity: 100,
},
},
}},
name: "foo",
values: []string{"bar", "baz"},
wantErr: true,
},
"delete list value - one value not present": {
gs: GameServer{Status: GameServerStatus{
Lists: map[string]ListStatus{
"foo": {
Values: []string{"foo", "bar", "bax"},
Capacity: 100,
},
},
}},
name: "foo",
values: []string{"bar", "baz"},
wantErr: false,
want: ListStatus{
Values: []string{"foo", "bax"},
Capacity: 100,
},
},
}

for test, testCase := range testCases {
t.Run(test, func(t *testing.T) {
err := testCase.gs.DeleteListValues(testCase.name, testCase.values)
if err != nil {
assert.True(t, testCase.wantErr)
} else {
assert.False(t, testCase.wantErr)
}
if list, ok := testCase.gs.Status.Lists[testCase.name]; ok {
assert.Equal(t, testCase.want, list)
}
})
}
}

func TestMergeRemoveDuplicates(t *testing.T) {
t.Parallel()

9 changes: 9 additions & 0 deletions pkg/apis/allocation/v1/gameserverallocation.go
Original file line number Diff line number Diff line change
@@ -209,6 +209,9 @@ type ListAction struct {
// AddValues appends values to a List's Values array. Any duplicate values will be ignored.
// +optional
AddValues []string `json:"addValues,omitempty"`
// DeleteValues removes values from a List's Values array. Any nonexistant values will be ignored.
// +optional
DeleteValues []string `json:"deleteValues,omitempty"`
// Capacity updates the maximum capacity of the Counter to this number. Min 0, Max 1000.
// +optional
Capacity *int64 `json:"capacity,omitempty"`
@@ -349,6 +352,12 @@ func (la *ListAction) ListActions(list string, gs *agonesv1.GameServer) error {
errs = errors.Join(errs, cntErr)
}
}
if len(la.DeleteValues) > 0 {
cntErr := gs.DeleteListValues(list, la.DeleteValues)
if cntErr != nil {
errs = errors.Join(errs, cntErr)
}
}
return errs
}

12 changes: 7 additions & 5 deletions pkg/apis/allocation/v1/gameserverallocation_test.go
Original file line number Diff line number Diff line change
@@ -1019,20 +1019,21 @@ func TestGameServerListActions(t *testing.T) {
},
"update list values and capacity": {
la: ListAction{
AddValues: []string{"magician1", "magician3"},
Capacity: int64Pointer(42),
AddValues: []string{"magician1", "magician3"},
Capacity: int64Pointer(42),
DeleteValues: []string{"magician2", "magician5", "magician6"},
},
list: "magicians",
gs: &agonesv1.GameServer{Status: agonesv1.GameServerStatus{
Lists: map[string]agonesv1.ListStatus{
"magicians": {
Values: []string{"magician1", "magician2"},
Values: []string{"magician1", "magician2", "magician4", "magician5"},
Capacity: 100,
}}}},
want: &agonesv1.GameServer{Status: agonesv1.GameServerStatus{
Lists: map[string]agonesv1.ListStatus{
"magicians": {
Values: []string{"magician1", "magician2", "magician3"},
Values: []string{"magician1", "magician4", "magician3"},
Capacity: 42,
}}}},
wantErr: false,
@@ -1263,7 +1264,8 @@ func TestValidateListActions(t *testing.T) {
Capacity: int64Pointer(0),
},
"baz": {
AddValues: []string{},
AddValues: []string{},
DeleteValues: []string{"good", "bye"},
},
},
wantErr: false,
5 changes: 5 additions & 0 deletions pkg/apis/allocation/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions pkg/gameserverallocations/allocator_test.go
Original file line number Diff line number Diff line change
@@ -309,7 +309,7 @@ func TestAllocatorApplyAllocationToGameServerCountsListsActions(t *testing.T) {
Status: agonesv1.GameServerStatus{NodeName: "node1", State: agonesv1.GameServerStateReady,
Lists: map[string]agonesv1.ListStatus{
"players": {
Values: []string{},
Values: []string{"alice", "bob", "cat"},
Capacity: 100,
},
},
@@ -339,7 +339,7 @@ func TestAllocatorApplyAllocationToGameServerCountsListsActions(t *testing.T) {
wantCounters map[string]agonesv1.CounterStatus
wantLists map[string]agonesv1.ListStatus
}{
"CounterActions increment and ListActions append and update capacity": {
"CounterActions increment and ListActions add, delete, and update capacity": {
features: fmt.Sprintf("%s=true", runtime.FeatureCountsAndLists),
gs: &gs1,
gsa: &allocationv1.GameServerAllocation{
@@ -356,8 +356,9 @@ func TestAllocatorApplyAllocationToGameServerCountsListsActions(t *testing.T) {
}},
Lists: map[string]allocationv1.ListAction{
"players": {
AddValues: []string{"x7un", "8inz"},
Capacity: &FORTY,
AddValues: []string{"x7un", "8inz"},
Capacity: &FORTY,
DeleteValues: []string{"bob"},
}}}},
wantCounters: map[string]agonesv1.CounterStatus{
"rooms": {
@@ -366,7 +367,7 @@ func TestAllocatorApplyAllocationToGameServerCountsListsActions(t *testing.T) {
}},
wantLists: map[string]agonesv1.ListStatus{
"players": {
Values: []string{"x7un", "8inz"},
Values: []string{"alice", "cat", "x7un", "8inz"},
Capacity: 40,
}},
},
28 changes: 15 additions & 13 deletions proto/allocation/allocation.proto
Original file line number Diff line number Diff line change
@@ -90,12 +90,12 @@ message AllocationRequest {
//
// For `Distributed` strategy sorting, the entire selection of `GameServers` will be sorted by this priority list to provide the
// order that `GameServers` will be allocated by.
repeated Priority priorities = 9;
repeated Priority priorities = 9;

// [Stage: Beta]
// [FeatureFlag:CountsAndLists]
// Counters and Lists provide a set of actions to perform
// on Counters and Lists during allocation.
// on Counters and Lists during allocation.
map<string, CounterAction> counters = 10;
map<string, ListAction> lists = 11;
}
@@ -191,20 +191,20 @@ message PlayerSelector {
// CounterSelector is the filter options for a GameServer based on the count and/or available capacity.
// 0 for MaxCount or MaxAvailable means unlimited maximum. Default for all fields: 0
message CounterSelector {
int64 minCount = 1;
int64 maxCount = 2;
int64 minAvailable = 3;
int64 maxAvailable = 4;
int64 minCount = 1;
int64 maxCount = 2;
int64 minAvailable = 3;
int64 maxAvailable = 4;
}

// ListSelector is the filter options for a GameServer based on List available capacity and/or the
// existence of a value in a List.
// 0 for MaxAvailable means unlimited maximum. Default for integer fields: 0
// "" for ContainsValue means ignore field. Default for string field: ""
message ListSelector {
string containsValue = 1;
int64 minAvailable = 2;
int64 maxAvailable = 3;
string containsValue = 1;
int64 minAvailable = 2;
int64 maxAvailable = 3;
}

// Priority is a sorting option for GameServers with Counters or Lists based on the Capacity.
@@ -232,14 +232,16 @@ message Priority {
// Capacity: Update the maximum capacity of the Counter to this number (optional). Min 0, Max int64.
message CounterAction {
google.protobuf.StringValue action = 1;
google.protobuf.Int64Value amount = 2;
google.protobuf.Int64Value capacity = 3;
google.protobuf.Int64Value amount = 2;
google.protobuf.Int64Value capacity = 3;
}

// ListAction is an optional action that can be performed on a List at allocation.
// AddValues: Append values to a List's Values array (optional). Any duplicate values will be ignored.
// Capacity: Update the maximum capacity of the Counter to this number (optional). Min 0, Max 1000.
// DeleteValues: Remove values from a List's Values array (optional). Any nonexistant values will be ignored.
message ListAction {
repeated string addValues = 1;
google.protobuf.Int64Value capacity = 2;
repeated string addValues = 1;
google.protobuf.Int64Value capacity = 2;
repeated string deleteValues = 3;
}
28 changes: 15 additions & 13 deletions sdks/rust/proto/allocation/allocation.proto
Original file line number Diff line number Diff line change
@@ -90,12 +90,12 @@ message AllocationRequest {
//
// For `Distributed` strategy sorting, the entire selection of `GameServers` will be sorted by this priority list to provide the
// order that `GameServers` will be allocated by.
repeated Priority priorities = 9;
repeated Priority priorities = 9;

// [Stage: Beta]
// [FeatureFlag:CountsAndLists]
// Counters and Lists provide a set of actions to perform
// on Counters and Lists during allocation.
// on Counters and Lists during allocation.
map<string, CounterAction> counters = 10;
map<string, ListAction> lists = 11;
}
@@ -191,20 +191,20 @@ message PlayerSelector {
// CounterSelector is the filter options for a GameServer based on the count and/or available capacity.
// 0 for MaxCount or MaxAvailable means unlimited maximum. Default for all fields: 0
message CounterSelector {
int64 minCount = 1;
int64 maxCount = 2;
int64 minAvailable = 3;
int64 maxAvailable = 4;
int64 minCount = 1;
int64 maxCount = 2;
int64 minAvailable = 3;
int64 maxAvailable = 4;
}

// ListSelector is the filter options for a GameServer based on List available capacity and/or the
// existence of a value in a List.
// 0 for MaxAvailable means unlimited maximum. Default for integer fields: 0
// "" for ContainsValue means ignore field. Default for string field: ""
message ListSelector {
string containsValue = 1;
int64 minAvailable = 2;
int64 maxAvailable = 3;
string containsValue = 1;
int64 minAvailable = 2;
int64 maxAvailable = 3;
}

// Priority is a sorting option for GameServers with Counters or Lists based on the Capacity.
@@ -232,14 +232,16 @@ message Priority {
// Capacity: Update the maximum capacity of the Counter to this number (optional). Min 0, Max int64.
message CounterAction {
google.protobuf.StringValue action = 1;
google.protobuf.Int64Value amount = 2;
google.protobuf.Int64Value capacity = 3;
google.protobuf.Int64Value amount = 2;
google.protobuf.Int64Value capacity = 3;
}

// ListAction is an optional action that can be performed on a List at allocation.
// AddValues: Append values to a List's Values array (optional). Any duplicate values will be ignored.
// Capacity: Update the maximum capacity of the Counter to this number (optional). Min 0, Max 1000.
// DeleteValues: Remove values from a List's Values array (optional). Any nonexistant values will be ignored.
message ListAction {
repeated string addValues = 1;
google.protobuf.Int64Value capacity = 2;
repeated string addValues = 1;
google.protobuf.Int64Value capacity = 2;
repeated string deleteValues = 3;
}
16 changes: 14 additions & 2 deletions site/content/en/docs/Guides/access-api.md
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ description: >
---

Installing Agones creates several [Custom Resource Definitions (CRD)](https://kubernetes.io/docs/concepts/api-extension/custom-resources),
which can be accessed and manipulated through the Kubernetes API.
which can be accessed and manipulated through the Kubernetes API.

The detailed list of Agones CRDs with their parameters could be found here - [Agones CRD API Reference](../../reference/agones_crd_api_reference/).

@@ -402,7 +402,19 @@ curl http://localhost:8001/apis/agones.dev/v1/namespaces/default/gameservers

### Allocate a gameserver from a fleet named 'simple-game-server', with GameServerAllocation
```bash
curl -d '{"apiVersion":"allocation.agones.dev/v1","kind":"GameServerAllocation","spec":{"required":{"matchLabels":{"agones.dev/fleet":"simple-game-server"}}}}' -H "Content-Type: application/json" -X POST http://localhost:8001/apis/allocation.agones.dev/v1/namespaces/default/gameserverallocations
curl -d '{
"apiVersion": "allocation.agones.dev/v1",
"kind": "GameServerAllocation",
"spec": {
"selectors": [
{
"matchLabels": {
"agones.dev/fleet": "simple-game-server"
}
}
]
}
}' -H "Content-Type: application/json" -X POST http://localhost:8001/apis/allocation.agones.dev/v1/namespaces/default/gameserverallocations
```
```
{
7 changes: 5 additions & 2 deletions site/content/en/docs/Reference/gameserverallocation.md
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ spec:
containsValue: "x6k8z" # only match GameServers who has this value in the list. Defaults to "", which is all.
minAvailable: 1 # minimum available (current capacity - current count). Defaults to 0.
maxAvailable: 10 # maximum available (current capacity - current count) Defaults to 0, which translates to max(int64)
# [Stage:Alpha]
# [Stage:Alpha]
# [FeatureFlag:PlayerAllocationFilter]
# Provides a filter on minimum and maximum values for player capacity when retrieving a GameServer
# through Allocation. Defaults to no limits.
@@ -111,6 +111,9 @@ spec:
- x7un
- 8inz
capacity: 40 # Updates the maximum capacity of the Counter to this number. Min 0, Max 1000.
deleteValues: # removes values from a List's Values array. Any nonexistant values are ignored.
- alice
- bob
{{< /tab >}}
{{< tab header="required & preferred (deprecated)" lang="yaml" >}}
apiVersion: "allocation.agones.dev/v1"
@@ -170,7 +173,7 @@ spec:
annotations:
map: garden22
{{< /tab >}}
{{< /tabpane >}}
{{< /tabpane >}}

The `spec` field is the actual `GameServerAllocation` specification, and it is composed as follows:

12 changes: 9 additions & 3 deletions test/e2e/allocator_test.go
Original file line number Diff line number Diff line change
@@ -352,7 +352,8 @@ func TestAllocatorWithCountersAndLists(t *testing.T) {
},
Lists: map[string]*pb.ListAction{
"rooms": {
AddValues: []string{"1"},
AddValues: []string{"1"},
DeleteValues: []string{"2"}, // This action is ignored. (Value does not exist.)
},
},
}
@@ -379,6 +380,7 @@ func TestAllocatorWithCountersAndLists(t *testing.T) {
assert.Contains(t, response.GetLists(), "rooms")
assert.Equal(t, int64(10), response.GetLists()["rooms"].Capacity.GetValue())
assert.EqualValues(t, request.Lists["rooms"].AddValues, response.GetLists()["rooms"].Values)
assert.NotEqualValues(t, request.Lists["rooms"].DeleteValues, response.GetLists()["rooms"].Values)
return true, nil
})
require.NoError(t, err)
@@ -405,6 +407,7 @@ func TestRestAllocatorWithCountersAndLists(t *testing.T) {
}
f.Spec.Template.Spec.Lists = map[string]agonesv1.ListStatus{
"rooms": {
Values: []string{"one", "two", "three"},
Capacity: 10,
},
}
@@ -434,7 +437,8 @@ func TestRestAllocatorWithCountersAndLists(t *testing.T) {
},
Lists: map[string]*pb.ListAction{
"rooms": {
AddValues: []string{"1"},
AddValues: []string{"1"},
DeleteValues: []string{"three", "one"},
},
},
}
@@ -478,7 +482,9 @@ func TestRestAllocatorWithCountersAndLists(t *testing.T) {
assert.Equal(t, int64(1), response.GetCounters()["players"].Count.GetValue())
assert.Contains(t, response.GetLists(), "rooms")
assert.Equal(t, int64(10), response.GetLists()["rooms"].Capacity.GetValue())
assert.EqualValues(t, request.Lists["rooms"].AddValues, response.GetLists()["rooms"].Values)
assert.Contains(t, response.GetLists()["rooms"].Values, request.Lists["rooms"].AddValues[0])
assert.NotContains(t, response.GetLists()["rooms"].Values, request.Lists["rooms"].DeleteValues[0])
assert.NotContains(t, response.GetLists()["rooms"].Values, request.Lists["rooms"].DeleteValues[1])
return true, nil
})
require.NoError(t, err)
7 changes: 4 additions & 3 deletions test/e2e/fleetautoscaler_test.go
Original file line number Diff line number Diff line change
@@ -1386,7 +1386,7 @@ func TestListAutoscalerAllocated(t *testing.T) {
defaultFlt := defaultFleet(framework.Namespace)
defaultFlt.Spec.Template.Spec.Lists = map[string]agonesv1.ListStatus{
"gamers": {
Values: []string{},
Values: []string{"gamer5", "gamer6"},
Capacity: 6, // AggregateCapacity 18
},
}
@@ -1441,7 +1441,7 @@ func TestListAutoscalerAllocated(t *testing.T) {
defer client.Fleets(framework.Namespace).Delete(ctx, flt.ObjectMeta.Name, metav1.DeleteOptions{}) // nolint:errcheck
framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

// Adds 4 gamers to each allocated gameserver.
// Adds 4 gamers to each allocated gameserver, and removes 2 existing gamers.
gsa := allocationv1.GameServerAllocation{
Spec: allocationv1.GameServerAllocationSpec{
Selectors: []allocationv1.GameServerSelector{
@@ -1450,7 +1450,8 @@ func TestListAutoscalerAllocated(t *testing.T) {
},
Lists: map[string]allocationv1.ListAction{
"gamers": {
AddValues: []string{"gamer1", "gamer2", "gamer3", "gamer4"},
AddValues: []string{"gamer1", "gamer2", "gamer3", "gamer4"},
DeleteValues: []string{"gamer5", "gamer6"},
}}}}

// Allocate game servers, as Buffer Percent scales up (or down) based on allocated aggregate capacity
25 changes: 23 additions & 2 deletions test/e2e/gameserverallocation_test.go
Original file line number Diff line number Diff line change
@@ -877,6 +877,10 @@ func TestListGameServerAllocationActions(t *testing.T) {
Values: []string{"player0", "player1", "player2"},
Capacity: 8,
}
lists["rooms"] = agonesv1.ListStatus{
Values: []string{"room0", "room1", "room2"},
Capacity: 20,
}

flt := defaultFleet(framework.Namespace)
flt.Spec.Template.Spec.Lists = lists
@@ -893,6 +897,7 @@ func TestListGameServerAllocationActions(t *testing.T) {

testCases := map[string]struct {
gsa allocationv1.GameServerAllocation
listName string
wantGsaErr bool
wantCapacity *int64
wantValues []string
@@ -907,6 +912,7 @@ func TestListGameServerAllocationActions(t *testing.T) {
"players": {
AddValues: []string{"player3", "player4", "player5"},
}}}},
listName: "players",
wantGsaErr: false,
wantValues: []string{"player0", "player1", "player2", "player3", "player4", "player5"},
},
@@ -920,10 +926,25 @@ func TestListGameServerAllocationActions(t *testing.T) {
"players": {
Capacity: &one,
}}}},
listName: "players",
wantGsaErr: false,
wantValues: []string{"player0"},
wantCapacity: &one,
},
"delete List values": {
gsa: allocationv1.GameServerAllocation{
Spec: allocationv1.GameServerAllocationSpec{
Selectors: []allocationv1.GameServerSelector{
{LabelSelector: fleetSelector},
},
Lists: map[string]allocationv1.ListAction{
"rooms": {
DeleteValues: []string{"room1", "room0"},
}}}},
listName: "rooms",
wantGsaErr: false,
wantValues: []string{"room2"},
},
}

for name, testCase := range testCases {
@@ -936,7 +957,7 @@ func TestListGameServerAllocationActions(t *testing.T) {
}
require.NoError(t, err)
assert.Equal(t, string(allocated), string(gsa.Status.State))
listStatus, ok := gsa.Status.Lists["players"]
listStatus, ok := gsa.Status.Lists[testCase.listName]
assert.True(t, ok)
if testCase.wantCapacity != nil {
assert.Equal(t, *testCase.wantCapacity, listStatus.Capacity)
@@ -948,7 +969,7 @@ func TestListGameServerAllocationActions(t *testing.T) {
assert.Equal(t, allocated, gs1.Status.State)
assert.NotNil(t, gs1.ObjectMeta.Annotations["agones.dev/last-allocated"])

list, ok := gs1.Status.Lists["players"]
list, ok := gs1.Status.Lists[testCase.listName]
assert.True(t, ok)
if testCase.wantCapacity != nil {
assert.Equal(t, *testCase.wantCapacity, list.Capacity)

0 comments on commit 3c5b7df

Please sign in to comment.