From efbc412d7e8e486767c8b0410927c1ff5e0b57a6 Mon Sep 17 00:00:00 2001
From: lacroixthomas
Date: Tue, 2 Apr 2024 21:44:25 -0400
Subject: [PATCH] Feat/counter and list defaulting order to ascending (#3734)
* 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
---
install/helm/agones/templates/crds/fleet.yaml | 1 +
install/yaml/install.yaml | 1 +
pkg/apis/agones/v1/common.go | 1 +
.../allocation/v1/gameserverallocation.go | 6 +
.../v1/gameserverallocation_test.go | 12 +-
.../Reference/agones_crd_api_reference.html | 785 +++++++++---------
6 files changed, 413 insertions(+), 393 deletions(-)
diff --git a/install/helm/agones/templates/crds/fleet.yaml b/install/helm/agones/templates/crds/fleet.yaml
index 1c68f1a474..36da1d6681 100644
--- a/install/helm/agones/templates/crds/fleet.yaml
+++ b/install/helm/agones/templates/crds/fleet.yaml
@@ -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
diff --git a/install/yaml/install.yaml b/install/yaml/install.yaml
index eb4f50b1f7..aa7cc71250 100644
--- a/install/yaml/install.yaml
+++ b/install/yaml/install.yaml
@@ -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
diff --git a/pkg/apis/agones/v1/common.go b/pkg/apis/agones/v1/common.go
index c1bd11f9bc..5c0c7e2ea8 100644
--- a/pkg/apis/agones/v1/common.go
+++ b/pkg/apis/agones/v1/common.go
@@ -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"`
}
diff --git a/pkg/apis/allocation/v1/gameserverallocation.go b/pkg/apis/allocation/v1/gameserverallocation.go
index 6e76e32e3e..558bff5b0e 100644
--- a/pkg/apis/allocation/v1/gameserverallocation.go
+++ b/pkg/apis/allocation/v1/gameserverallocation.go
@@ -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()
diff --git a/pkg/apis/allocation/v1/gameserverallocation_test.go b/pkg/apis/allocation/v1/gameserverallocation_test.go
index d118813440..0c6c28fb48 100644
--- a/pkg/apis/allocation/v1/gameserverallocation_test.go
+++ b/pkg/apis/allocation/v1/gameserverallocation_test.go
@@ -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()
diff --git a/site/content/en/docs/Reference/agones_crd_api_reference.html b/site/content/en/docs/Reference/agones_crd_api_reference.html
index 2a47f9f767..c1957b29da 100644
--- a/site/content/en/docs/Reference/agones_crd_api_reference.html
+++ b/site/content/en/docs/Reference/agones_crd_api_reference.html
@@ -4379,6 +4379,9 @@ WebhookPolicy
Packages:
-agones.dev/v1
+multicluster.agones.dev/v1
Package v1 is the v1 version of the API.
Resource Types:
-Fleet
+GameServerAllocationPolicy
-
Fleet is the data structure for a Fleet resource
+GameServerAllocationPolicy is the Schema for the gameserverallocationpolicies API
@@ -4422,7 +4418,7 @@ Fleet
string
-agones.dev/v1
+multicluster.agones.dev/v1
|
@@ -4431,7 +4427,7 @@ Fleet
kind
string
-Fleet |
+GameServerAllocationPolicy |
@@ -4451,8 +4447,8 @@
-replicas
+priority
int32
|
- Replicas are the number of GameServers that should be in this set. Defaults to 0.
|
-allocationOverflow
+weight
-
-AllocationOverflow
-
+int
|
-(Optional)
- Labels and/or Annotations to apply to overflowing GameServers when the number of Allocated GameServers is more
-than the desired replicas on the underlying GameServerSet
|
-strategy
+connectionInfo
-
-Kubernetes apps/v1.DeploymentStrategy
+
+ClusterConnectionInfo
|
- Deployment strategy
|
+
+ |
+
+
+
+ClusterConnectionInfo
+
+
+(Appears on:
+GameServerAllocationPolicySpec)
+
+
+
ClusterConnectionInfo defines the connection information for a cluster
+
+
+
+
+Field |
+Description |
+
+
+
-scheduling
+clusterName
-agones.dev/agones/pkg/apis.SchedulingStrategy
+string
|
- Scheduling strategy. Defaults to “Packed”.
+Optional: the name of the targeted cluster
|
-priorities
+allocationEndpoints
-
-[]Priority
-
+[]string
|
-(Optional)
- [Stage: Alpha]
-[FeatureFlag:CountsAndLists]
-Priorities configuration alters scale down logic in Fleets based on the configured available capacity order under that key.
-Priority of sorting is in descending importance. I.e. The position 0 priority entry is checked first.
-For Packed strategy scale down, this priority list will be the tie-breaker within the node, to ensure optimal
-infrastructure usage while also allowing some custom prioritisation of GameServers .
-For Distributed strategy scale down, the entire Fleet will be sorted by this priority list to provide the
-order of GameServers to delete on scale down.
+The endpoints for the allocator service in the targeted cluster.
+If the AllocationEndpoints is not set, the allocation happens on local cluster.
+If there are multiple endpoints any of the endpoints that can handle allocation request should suffice
|
-template
+secretName
-
-GameServerTemplateSpec
-
+string
|
- Template the GameServer template to apply for this Fleet
+The name of the secret that contains TLS client certificates to connect the allocator server in the targeted cluster
|
-
+
+
+namespace
+
+string
+
+ |
+
+ The cluster namespace from which to allocate gameservers
|
-status
+serverCa
-
-FleetStatus
-
+[]byte
|
+ The PEM encoded server CA, used by the allocator client to authenticate the remote server.
|
-GameServer
+ConnectionInfoIterator
-
GameServer is the data structure for a GameServer resource.
-It is worth noting that while there is a GameServerStatus
Status entry for the GameServer
, it is not
-defined as a subresource - unlike Fleet
and other Agones resources.
-This is so that we can retain the ability to change multiple aspects of a GameServer
in a single atomic operation,
-which is particularly useful for operations such as allocation.
+ConnectionInfoIterator an iterator on ClusterConnectionInfo
@@ -4580,108 +4584,393 @@ GameServer
-apiVersion
-string |
+currPriority
+
+int
+
+
-
-agones.dev/v1
-
+currPriority Current priority index from the orderedPriorities
|
-kind
-string
+orderedPriorities
+
+[]int32
+
+ |
+
+ orderedPriorities list of ordered priorities
|
-GameServer |
-metadata
+priorityToCluster
-
-Kubernetes meta/v1.ObjectMeta
-
+map[int32]map[string][]*agones.dev/agones/pkg/apis/multicluster/v1.GameServerAllocationPolicy
|
-Refer to the Kubernetes API documentation for the fields of the
-metadata field.
+priorityToCluster Map of priority to cluster-policies map
|
-spec
+clusterBlackList
-
-GameServerSpec
-
+map[string]bool
|
-
-
+clusterBlackList the cluster blacklist for the clusters that has already returned
+ |
+
+
+
+GameServerAllocationPolicySpec
+
+
+(Appears on:
+GameServerAllocationPolicy)
+
+
+
GameServerAllocationPolicySpec defines the desired state of GameServerAllocationPolicy
+
+
+
+Field |
+Description |
+
+
+
-container
+priority
-string
+int32
|
- Container specifies which Pod container is the game server. Only required if there is more than one
-container defined
|
-ports
+weight
-
-[]GameServerPort
-
+int
|
- Ports are the array of ports that can be exposed via the game server
|
-health
+connectionInfo
-
-Health
+
+ClusterConnectionInfo
|
- Health configures health checking
|
+
+
+
+agones.dev/v1
+
+
Package v1 is the v1 version of the API.
+
+Resource Types:
+
+Fleet
+
+
+
Fleet is the data structure for a Fleet resource
+
+
+
+
+Field |
+Description |
+
+
+
-scheduling
-
-agones.dev/agones/pkg/apis.SchedulingStrategy
-
+apiVersion
+string |
+
+
+agones.dev/v1
+
|
+
+
- Scheduling strategy. Defaults to “Packed”
+kind
+string
|
+Fleet |
-sdkServer
+metadata
-
-SdkServer
+
+Kubernetes meta/v1.ObjectMeta
|
- SdkServer specifies parameters for the Agones SDK Server sidecar container
+Refer to the Kubernetes API documentation for the fields of the
+metadata field.
+ |
+
+
+
+spec
+
+
+FleetSpec
+
+
+ |
+
+
+
+
+
+
+replicas
+
+int32
+
+ |
+
+ Replicas are the number of GameServers that should be in this set. Defaults to 0.
+ |
+
+
+
+allocationOverflow
+
+
+AllocationOverflow
+
+
+ |
+
+(Optional)
+ Labels and/or Annotations to apply to overflowing GameServers when the number of Allocated GameServers is more
+than the desired replicas on the underlying GameServerSet
+ |
+
+
+
+strategy
+
+
+Kubernetes apps/v1.DeploymentStrategy
+
+
+ |
+
+ Deployment strategy
+ |
+
+
+
+scheduling
+
+agones.dev/agones/pkg/apis.SchedulingStrategy
+
+ |
+
+ Scheduling strategy. Defaults to “Packed”.
+ |
+
+
+
+priorities
+
+
+[]Priority
+
+
+ |
+
+(Optional)
+ [Stage: Alpha]
+[FeatureFlag:CountsAndLists]
+Priorities configuration alters scale down logic in Fleets based on the configured available capacity order under that key.
+Priority of sorting is in descending importance. I.e. The position 0 priority entry is checked first.
+For Packed strategy scale down, this priority list will be the tie-breaker within the node, to ensure optimal
+infrastructure usage while also allowing some custom prioritisation of GameServers .
+For Distributed strategy scale down, the entire Fleet will be sorted by this priority list to provide the
+order of GameServers to delete on scale down.
+ |
+
+
+
+template
+
+
+GameServerTemplateSpec
+
+
+ |
+
+ Template the GameServer template to apply for this Fleet
+ |
+
+
+ |
+
+
+
+status
+
+
+FleetStatus
+
+
+ |
+
+ |
+
+
+
+GameServer
+
+
+
GameServer is the data structure for a GameServer resource.
+It is worth noting that while there is a GameServerStatus
Status entry for the GameServer
, it is not
+defined as a subresource - unlike Fleet
and other Agones resources.
+This is so that we can retain the ability to change multiple aspects of a GameServer
in a single atomic operation,
+which is particularly useful for operations such as allocation.
+
+
+
+
+Field |
+Description |
+
+
+
+
+
+apiVersion
+string |
+
+
+agones.dev/v1
+
+ |
+
+
+
+kind
+string
+ |
+GameServer |
+
+
+
+metadata
+
+
+Kubernetes meta/v1.ObjectMeta
+
+
+ |
+
+Refer to the Kubernetes API documentation for the fields of the
+metadata field.
+ |
+
+
+
+spec
+
+
+GameServerSpec
+
+
+ |
+
+
+
+
+
+
+container
+
+string
+
+ |
+
+ Container specifies which Pod container is the game server. Only required if there is more than one
+container defined
+ |
+
+
+
+ports
+
+
+[]GameServerPort
+
+
+ |
+
+ Ports are the array of ports that can be exposed via the game server
+ |
+
+
+
+health
+
+
+Health
+
+
+ |
+
+ Health configures health checking
+ |
+
+
+
+scheduling
+
+agones.dev/agones/pkg/apis.SchedulingStrategy
+
+ |
+
+ Scheduling strategy. Defaults to “Packed”
+ |
+
+
+
+sdkServer
+
+
+SdkServer
+
+
+ |
+
+ SdkServer specifies parameters for the Agones SDK Server sidecar container
|
@@ -6505,7 +6794,8 @@ Priority
Order: Sort by “Ascending” or “Descending”. “Descending” a bigger available capacity is preferred.
-“Ascending” would be smaller available capacity is preferred.
+“Ascending” would be smaller available capacity is preferred.
+The default sort order is “Ascending”
|
@@ -8472,295 +8762,6 @@ WebhookPolicy
-multicluster.agones.dev/v1
-
- Package v1 is the v1 version of the API.
-
-Resource Types:
-
-GameServerAllocationPolicy
-
-
- GameServerAllocationPolicy is the Schema for the gameserverallocationpolicies API
-
-
-
-
-Field |
-Description |
-
-
-
-
-
-apiVersion
-string |
-
-
-multicluster.agones.dev/v1
-
- |
-
-
-
-kind
-string
- |
-GameServerAllocationPolicy |
-
-
-
-metadata
-
-
-Kubernetes meta/v1.ObjectMeta
-
-
- |
-
-Refer to the Kubernetes API documentation for the fields of the
-metadata field.
- |
-
-
-
-spec
-
-
-GameServerAllocationPolicySpec
-
-
- |
-
-
-
-
-
-
-priority
-
-int32
-
- |
-
- |
-
-
-
-weight
-
-int
-
- |
-
- |
-
-
-
-connectionInfo
-
-
-ClusterConnectionInfo
-
-
- |
-
- |
-
-
- |
-
-
-
-ClusterConnectionInfo
-
-
-(Appears on:
-GameServerAllocationPolicySpec)
-
-
- ClusterConnectionInfo defines the connection information for a cluster
-
-
-
-
-Field |
-Description |
-
-
-
-
-
-clusterName
-
-string
-
- |
-
- Optional: the name of the targeted cluster
- |
-
-
-
-allocationEndpoints
-
-[]string
-
- |
-
- The endpoints for the allocator service in the targeted cluster.
-If the AllocationEndpoints is not set, the allocation happens on local cluster.
-If there are multiple endpoints any of the endpoints that can handle allocation request should suffice
- |
-
-
-
-secretName
-
-string
-
- |
-
- The name of the secret that contains TLS client certificates to connect the allocator server in the targeted cluster
- |
-
-
-
-namespace
-
-string
-
- |
-
- The cluster namespace from which to allocate gameservers
- |
-
-
-
-serverCa
-
-[]byte
-
- |
-
- The PEM encoded server CA, used by the allocator client to authenticate the remote server.
- |
-
-
-
-ConnectionInfoIterator
-
-
- ConnectionInfoIterator an iterator on ClusterConnectionInfo
-
-
-
-
-Field |
-Description |
-
-
-
-
-
-currPriority
-
-int
-
- |
-
- currPriority Current priority index from the orderedPriorities
- |
-
-
-
-orderedPriorities
-
-[]int32
-
- |
-
- orderedPriorities list of ordered priorities
- |
-
-
-
-priorityToCluster
-
-map[int32]map[string][]*agones.dev/agones/pkg/apis/multicluster/v1.GameServerAllocationPolicy
-
- |
-
- priorityToCluster Map of priority to cluster-policies map
- |
-
-
-
-clusterBlackList
-
-map[string]bool
-
- |
-
- clusterBlackList the cluster blacklist for the clusters that has already returned
- |
-
-
-
-GameServerAllocationPolicySpec
-
-
-(Appears on:
-GameServerAllocationPolicy)
-
-
- GameServerAllocationPolicySpec defines the desired state of GameServerAllocationPolicy
-
-
-
-
-Field |
-Description |
-
-
-
-
-
-priority
-
-int32
-
- |
-
- |
-
-
-
-weight
-
-int
-
- |
-
- |
-
-
-
-connectionInfo
-
-
-ClusterConnectionInfo
-
-
- |
-
- |
-
-
-
-
Generated with gen-crd-api-reference-docs .
|