Skip to content

Commit

Permalink
Change FleetAutoScaler policy for CountsAndLists to never scale to zero
Browse files Browse the repository at this point in the history
  • Loading branch information
igooch committed Oct 12, 2023
1 parent d5e2d12 commit 30bc00d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
10 changes: 6 additions & 4 deletions pkg/fleetautoscalers/fleetautoscalers.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,9 @@ func scaleDownLimited(f *agonesv1.Fleet, gameServerLister listeragonesv1.GameSer
replicas--
}

if replicas < 0 { // This shouldn't ever happen, but putting it here just in case.
replicas = 0
// We are not currently able to scale down to zero replicas, so one replica is the minimum allowed
if replicas < 1 {
replicas = 1
}

return replicas, true, nil
Expand Down Expand Up @@ -520,8 +521,9 @@ func scaleDown(f *agonesv1.Fleet, gameServerLister listeragonesv1.GameServerList
}
}

if replicas < 0 { // This shouldn't ever happen, but putting it here just in case.
replicas = 0
// We are not currently able to scale down to zero replicas, so one replica is the minimum allowed.
if replicas < 1 {
replicas = 1
}

return replicas, false, nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/fleetautoscalers/fleetautoscalers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,6 @@ func TestApplyCounterPolicy(t *testing.T) {
Capacity: 7}
}),
featureFlags: string(utilruntime.FeatureCountsAndLists) + "=true",
// TODO: Is this what we want (replica = 0 if MaxCapcity < per Counter Capacity)? If buffer = 1 then must be at least replica = 1? Or Max Capacity takes precedence?
cp: &autoscalingv1.CounterPolicy{
Key: "rooms",
MaxCapacity: 2,
Expand All @@ -1208,7 +1207,7 @@ func TestApplyCounterPolicy(t *testing.T) {
Capacity: 7,
}}}}},
want: expected{
replicas: 0,
replicas: 1,
limited: true,
wantErr: false,
},
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/fleetautoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ func TestCounterAutoscaler(t *testing.T) {
wantFasErr: false,
wantReplicas: 9,
},
"Scale Down to MaxCapacity": { // TODO: Not working here (but works in pkg/fleetautoscalers/fleetautoscalers_test.go)
"Scale Down to MaxCapacity": {
fas: counterFas(func(fap *autoscalingv1.FleetAutoscalerPolicy) {
fap.Counter = &autoscalingv1.CounterPolicy{
Key: "sessions",
Expand Down Expand Up @@ -915,6 +915,10 @@ func TestCounterAutoscaler(t *testing.T) {
return
}
assert.NoError(t, err)
list, err := framework.ListGameServersFromFleet(flt)
for _, gs := range list {
log.WithField("Counter", gs.Status.Counters).Info("GAME SERVER COUNTERS")
}
defer fleetautoscalers.Delete(ctx, fas.ObjectMeta.Name, metav1.DeleteOptions{}) // nolint:errcheck

framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(testCase.wantReplicas))
Expand Down

0 comments on commit 30bc00d

Please sign in to comment.