Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Counts and Lists Aggregate Values for Fleet Status and GameServerSet Status #3180

Merged
merged 9 commits into from
Jun 1, 2023
20 changes: 7 additions & 13 deletions install/helm/agones/templates/crds/gameserverset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,12 @@ spec:
additionalProperties:
type: object
properties:
count: # initial count
count: # Aggregated count of the Counter across the GameServerSet
type: integer
default: 0
minimum: 0
capacity: # max capacity of the counter
capacity: # Aggregated maximum capacity of the Counter across the GameServerSet
type: integer
default: 1000
minimum: 0
lists:
type: object
Expand All @@ -147,18 +146,13 @@ spec:
additionalProperties:
type: object
properties:
capacity: # max capacity of the array (can be less than or equal to value of maxItems)
capacity: # Aggregated maximum capacity of the List across the GameServerSet
type: integer
minimum: 0
default: 1000
maximum: 1000 # must be equal to values.maxItems
values:
type: array
x-kubernetes-list-type: set # Requires items in the array to be unique
maxItems: 1000 # max possible size of the value array (cannot be updated)
items: # name of the item (player1, session1, room1, etc.)
type: string
default: []
count: # Aggregated number of items in the List across the GameServerSet
type: integer
minimum: 0
default: 0
subresources:
# status enables the status subresource.
status: { }
Expand Down
20 changes: 7 additions & 13 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15517,13 +15517,12 @@ spec:
additionalProperties:
type: object
properties:
count: # initial count
count: # Aggregated count of the Counter across the GameServerSet
type: integer
default: 0
minimum: 0
capacity: # max capacity of the counter
capacity: # Aggregated maximum capacity of the Counter across the GameServerSet
type: integer
default: 1000
minimum: 0
lists:
type: object
Expand All @@ -15533,18 +15532,13 @@ spec:
additionalProperties:
type: object
properties:
capacity: # max capacity of the array (can be less than or equal to value of maxItems)
capacity: # Aggregated maximum capacity of the List across the GameServerSet
type: integer
minimum: 0
default: 1000
maximum: 1000 # must be equal to values.maxItems
values:
type: array
x-kubernetes-list-type: set # Requires items in the array to be unique
maxItems: 1000 # max possible size of the value array (cannot be updated)
items: # name of the item (player1, session1, room1, etc.)
type: string
default: []
count: # Aggregated number of items in the List across the GameServerSet
type: integer
minimum: 0
default: 0
subresources:
# status enables the status subresource.
status: { }
Expand Down
12 changes: 12 additions & 0 deletions pkg/apis/agones/v1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ type AggregatedPlayerStatus struct {
Capacity int64 `json:"capacity"`
}

// AggregatedCounterStatus stores total Counter tracking values
type AggregatedCounterStatus struct {
Count int64 `json:"count"`
Capacity int64 `json:"capacity"`
}

// AggregatedListStatus stores total List tracking values
type AggregatedListStatus struct {
Count int64 `json:"count"`
Capacity int64 `json:"capacity"`
}

// crd is an interface to get Name and Kind of CRD
type crd interface {
GetName() string
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/agones/v1/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ type FleetStatus struct {
// Players are the current total player capacity and count for this Fleet
// +optional
Players *AggregatedPlayerStatus `json:"players,omitempty"`
// (Alpha, CountsAndLists feature flag) Counters provides aggregated Counter capacity and Counter
// count for this Fleet.
// +optional
Counters map[string]AggregatedCounterStatus `json:"counters,omitempty"`
// (Alpha, CountsAndLists feature flag) Lists provides aggregated List capacityv and List values
// for this Fleet.
// +optional
Lists map[string]AggregatedListStatus `json:"lists,omitempty"`
}

// GameServerSet returns a single GameServerSet for this Fleet definition
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/agones/v1/gameserverset.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ type GameServerSetStatus struct {
// Players is the current total player capacity and count for this GameServerSet
// +optional
Players *AggregatedPlayerStatus `json:"players,omitempty"`
// (Alpha, CountsAndLists feature flag) Counters provides aggregated Counter capacity and Counter
// count for this GameServerSet.
// +optional
Counters map[string]AggregatedCounterStatus `json:"counters,omitempty"`
// (Alpha, CountsAndLists feature flag) Lists provides aggregated List capacity and List values
// for this GameServerSet.
// +optional
Lists map[string]AggregatedListStatus `json:"lists,omitempty"`
}

// ValidateUpdate validates when updates occur. The argument
Expand Down
60 changes: 60 additions & 0 deletions pkg/apis/agones/v1/zz_generated.deepcopy.go

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

48 changes: 48 additions & 0 deletions pkg/fleets/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,12 +652,20 @@ func (c *Controller) updateFleetStatus(ctx context.Context, fleet *agonesv1.Flee
fCopy.Status.ReadyReplicas = 0
fCopy.Status.ReservedReplicas = 0
fCopy.Status.AllocatedReplicas = 0
if runtime.FeatureEnabled(runtime.FeatureCountsAndLists) {
fCopy.Status.Counters = make(map[string]agonesv1.AggregatedCounterStatus)
fCopy.Status.Lists = make(map[string]agonesv1.AggregatedListStatus)
}

for _, gsSet := range list {
fCopy.Status.Replicas += gsSet.Status.Replicas
fCopy.Status.ReadyReplicas += gsSet.Status.ReadyReplicas
fCopy.Status.ReservedReplicas += gsSet.Status.ReservedReplicas
fCopy.Status.AllocatedReplicas += gsSet.Status.AllocatedReplicas
if runtime.FeatureEnabled(runtime.FeatureCountsAndLists) {
fCopy.Status.Counters = mergeCounters(fCopy.Status.Counters, gsSet.Status.Counters)
fCopy.Status.Lists = mergeLists(fCopy.Status.Lists, gsSet.Status.Lists)
}
}
if runtime.FeatureEnabled(runtime.FeaturePlayerTracking) {
// to make this code simpler, while the feature gate is in place,
Expand Down Expand Up @@ -693,3 +701,43 @@ func (c *Controller) filterGameServerSetByActive(fleet *agonesv1.Fleet, list []*

return active, rest
}

// mergeCounters adds the contents of AggregatedCounterStatus c2 into c1.
func mergeCounters(c1, c2 map[string]agonesv1.AggregatedCounterStatus) map[string]agonesv1.AggregatedCounterStatus {
if c1 == nil {
c1 = make(map[string]agonesv1.AggregatedCounterStatus)
}

for key, val := range c2 {
// If the Counter exists in both maps, aggregate the values.
igooch marked this conversation as resolved.
Show resolved Hide resolved
if counter, ok := c1[key]; ok {
counter.Capacity += val.Capacity
counter.Count += val.Count
c1[key] = counter
} else {
c1[key] = *val.DeepCopy()
}
}

return c1
}

// mergeLists adds the contents of AggregatedListStatus l2 into l1.
func mergeLists(l1, l2 map[string]agonesv1.AggregatedListStatus) map[string]agonesv1.AggregatedListStatus {
if l1 == nil {
l1 = make(map[string]agonesv1.AggregatedListStatus)
}

for key, val := range l2 {
// If the List exists in both maps, aggregate the values.
if list, ok := l1[key]; ok {
list.Capacity += val.Capacity
list.Count += val.Count
l1[key] = list
} else {
l1[key] = *val.DeepCopy()
}
}

return l1
}
Loading