Skip to content

Commit

Permalink
Feat/counter and list defaulting order to ascending (#3734)
Browse files Browse the repository at this point in the history
* feat(counter&list): Defaulting order to ascending in fleet crd

* feat(counter&list): Defaulting order to ascending in gameserverAllocation

* feat(counter&list): Update unit test

* feat(counter&list): Add default sort order in comment for priority

* feat(counter&list): Re-run make test-gen-api-docs to update doc
  • Loading branch information
lacroixthomas committed Apr 3, 2024
1 parent f4403e8 commit efbc412
Show file tree
Hide file tree
Showing 6 changed files with 413 additions and 393 deletions.
1 change: 1 addition & 0 deletions install/helm/agones/templates/crds/fleet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ spec:
order:
type: string
description: Ascending or Descending sort order. Default is "Ascending" so remove smaller available capacity first. "Descending" would remove larger available capacity first.
default: Ascending
enum:
- Ascending
- Descending
Expand Down
1 change: 1 addition & 0 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ spec:
order:
type: string
description: Ascending or Descending sort order. Default is "Ascending" so remove smaller available capacity first. "Descending" would remove larger available capacity first.
default: Ascending
enum:
- Ascending
- Descending
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/agones/v1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ type Priority struct {
Key string `json:"key"`
// Order: Sort by "Ascending" or "Descending". "Descending" a bigger available capacity is preferred.
// "Ascending" would be smaller available capacity is preferred.
// The default sort order is "Ascending"
Order string `json:"order"`
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/allocation/v1/gameserverallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,12 @@ func (gsa *GameServerAllocation) ApplyDefaults() {
gsa.Spec.Scheduling = apis.Packed
}

for i := range gsa.Spec.Priorities {
if len(gsa.Spec.Priorities[i].Order) == 0 {
gsa.Spec.Priorities[i].Order = agonesv1.GameServerPriorityAscending
}
}

if len(gsa.Spec.Selectors) == 0 {
gsa.Spec.Required.ApplyDefaults()

Expand Down
12 changes: 11 additions & 1 deletion pkg/apis/allocation/v1/gameserverallocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,19 @@ func TestGameServerAllocationApplyDefaults(t *testing.T) {

assert.Equal(t, apis.Packed, gsa.Spec.Scheduling)

gsa = &GameServerAllocation{Spec: GameServerAllocationSpec{Scheduling: apis.Distributed}}
priorities := []agonesv1.Priority{
{Type: agonesv1.GameServerPriorityList},
{Type: agonesv1.GameServerPriorityCounter},
}
expectedPrioritiesWithDefault := []agonesv1.Priority{
{Type: agonesv1.GameServerPriorityList, Order: agonesv1.GameServerPriorityAscending},
{Type: agonesv1.GameServerPriorityCounter, Order: agonesv1.GameServerPriorityAscending},
}

gsa = &GameServerAllocation{Spec: GameServerAllocationSpec{Scheduling: apis.Distributed, Priorities: priorities}}
gsa.ApplyDefaults()
assert.Equal(t, apis.Distributed, gsa.Spec.Scheduling)
assert.Equal(t, expectedPrioritiesWithDefault, gsa.Spec.Priorities)

runtime.FeatureTestMutex.Lock()
defer runtime.FeatureTestMutex.Unlock()
Expand Down
Loading

0 comments on commit efbc412

Please sign in to comment.