Skip to content

Commit

Permalink
Merge branch 'main' into testInPlaceUpgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
igooch authored Dec 2, 2024
2 parents 280ccb9 + cd9b7a1 commit fb32c69
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 3 deletions.
3 changes: 2 additions & 1 deletion install/helm/agones/templates/service/allocation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ spec:
targetPort: {{ .Values.agones.allocator.service.grpc.targetPort }}
{{- if .Values.agones.allocator.service.grpc.appProtocol }}
appProtocol: {{.Values.agones.allocator.service.grpc.appProtocol}}
{{- end}}
{{- end}}
{{- if eq .Values.agones.allocator.service.serviceType "NodePort" }}
nodePort: {{ .Values.agones.allocator.service.grpc.nodePort }}
{{- end }}
Expand All @@ -79,6 +79,7 @@ spec:
loadBalancerIP: {{ .Values.agones.allocator.service.loadBalancerIP }}
{{- end }}
{{- if eq .Values.agones.allocator.service.serviceType "LoadBalancer" }}
externalTrafficPolicy: {{ .Values.agones.allocator.service.externalTrafficPolicy }}
{{- if .Values.agones.allocator.service.loadBalancerSourceRanges }}
loadBalancerSourceRanges:
{{ toYaml .Values.agones.allocator.service.loadBalancerSourceRanges | indent 4 }}
Expand Down
1 change: 1 addition & 0 deletions install/helm/agones/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ agones:
service:
name: agones-allocator
serviceType: LoadBalancer
externalTrafficPolicy: Cluster
clusterIP: ""
loadBalancerIP: ""
loadBalancerSourceRanges: []
Expand Down
1 change: 1 addition & 0 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17822,6 +17822,7 @@ spec:
targetPort: 8443
protocol: TCP
type: LoadBalancer
externalTrafficPolicy: Cluster
---
# Source: agones/templates/service/allocation.yaml
apiVersion: v1
Expand Down
27 changes: 26 additions & 1 deletion pkg/fleetautoscalers/fleetautoscalers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,31 @@ func TestApplyCounterPolicy(t *testing.T) {
wantErr: true,
},
},
"Counter based fleet does not have any replicas": {
fleet: modifiedFleet(func(f *agonesv1.Fleet) {
f.Spec.Template.Spec.Counters = make(map[string]agonesv1.CounterStatus)
f.Spec.Template.Spec.Counters["gamers"] = agonesv1.CounterStatus{
Count: 0,
Capacity: 7}
f.Status.Replicas = 0
f.Status.ReadyReplicas = 0
f.Status.AllocatedReplicas = 0
f.Status.Counters = make(map[string]agonesv1.AggregatedCounterStatus)
f.Status.Counters["gamers"] = agonesv1.AggregatedCounterStatus{}
}),
featureFlags: string(utilruntime.FeatureCountsAndLists) + "=true",
cp: &autoscalingv1.CounterPolicy{
Key: "gamers",
MaxCapacity: 100,
MinCapacity: 10,
BufferSize: intstr.FromInt(10),
},
want: expected{
replicas: 2,
limited: true,
wantErr: false,
},
},
"fleet spec does not have counter": {
fleet: modifiedFleet(func(f *agonesv1.Fleet) {
f.Spec.Template.Spec.Counters = make(map[string]agonesv1.CounterStatus)
Expand Down Expand Up @@ -1570,7 +1595,7 @@ func TestApplyListPolicy(t *testing.T) {
wantErr: true,
},
},
"fleet does not have any replicas": {
"List based fleet does not have any replicas": {
fleet: modifiedFleet(func(f *agonesv1.Fleet) {
f.Spec.Template.Spec.Lists = make(map[string]agonesv1.ListStatus)
f.Spec.Template.Spec.Lists["gamers"] = agonesv1.ListStatus{
Expand Down
9 changes: 9 additions & 0 deletions pkg/gameserversets/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ func computeStatus(gsSet *agonesv1.GameServerSet, list []*agonesv1.GameServer) a
// Initialize list status with empty lists from spec
if runtime.FeatureEnabled(runtime.FeatureCountsAndLists) {
status.Lists = createInitialListStatus(gsSet)
status.Counters = createInitialCounterStatus(gsSet)
}
for _, gs := range list {
if gs.IsBeingDeleted() {
Expand Down Expand Up @@ -700,6 +701,14 @@ func createInitialListStatus(gsSet *agonesv1.GameServerSet) map[string]agonesv1.
return list
}

func createInitialCounterStatus(gsSet *agonesv1.GameServerSet) map[string]agonesv1.AggregatedCounterStatus {
counters := make(map[string]agonesv1.AggregatedCounterStatus)
for name := range gsSet.Spec.Template.Spec.Counters {
counters[name] = agonesv1.AggregatedCounterStatus{}
}
return counters
}

// aggregateCounters adds the contents of a CounterStatus map to an AggregatedCounterStatus map.
func aggregateCounters(aggCounterStatus map[string]agonesv1.AggregatedCounterStatus,
counterStatus map[string]agonesv1.CounterStatus,
Expand Down
40 changes: 39 additions & 1 deletion pkg/gameserversets/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,44 @@ func TestComputeStatus(t *testing.T) {
assert.Equal(t, expected, computeStatus(gsSet, list))
})

t.Run("counters with no gameservers", func(t *testing.T) {
utilruntime.FeatureTestMutex.Lock()
defer utilruntime.FeatureTestMutex.Unlock()

require.NoError(t, utilruntime.ParseFeatures(fmt.Sprintf("%s=true", utilruntime.FeatureCountsAndLists)))

gsSet := defaultFixture()
gsSet.Spec.Template.Spec.Counters = map[string]agonesv1.CounterStatus{
"firstCounter": {Capacity: 10, Count: 1},
"secondCounter": {Capacity: 10, Count: 1},
}
var list []*agonesv1.GameServer

expected := agonesv1.GameServerSetStatus{
Replicas: 0,
ReadyReplicas: 0,
ReservedReplicas: 0,
AllocatedReplicas: 0,
Lists: map[string]agonesv1.AggregatedListStatus{},
Counters: map[string]agonesv1.AggregatedCounterStatus{
"firstCounter": {
AllocatedCount: 0,
AllocatedCapacity: 0,
Capacity: 0,
Count: 0,
},
"secondCounter": {
AllocatedCount: 0,
AllocatedCapacity: 0,
Capacity: 0,
Count: 0,
},
},
}

assert.Equal(t, expected, computeStatus(gsSet, list))
})

t.Run("lists", func(t *testing.T) {
utilruntime.FeatureTestMutex.Lock()
defer utilruntime.FeatureTestMutex.Unlock()
Expand Down Expand Up @@ -484,7 +522,7 @@ func TestComputeStatus(t *testing.T) {
ReadyReplicas: 0,
ReservedReplicas: 0,
AllocatedReplicas: 0,
Counters: nil,
Counters: map[string]agonesv1.AggregatedCounterStatus{},
Lists: map[string]agonesv1.AggregatedListStatus{
"firstList": {
AllocatedCount: 0,
Expand Down
Loading

0 comments on commit fb32c69

Please sign in to comment.