diff --git a/pkg/fleetautoscalers/fleetautoscalers.go b/pkg/fleetautoscalers/fleetautoscalers.go index be7f516116..e1761ba3ff 100644 --- a/pkg/fleetautoscalers/fleetautoscalers.go +++ b/pkg/fleetautoscalers/fleetautoscalers.go @@ -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 @@ -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 diff --git a/pkg/fleetautoscalers/fleetautoscalers_test.go b/pkg/fleetautoscalers/fleetautoscalers_test.go index ee01aeeff1..9cf7e24c57 100644 --- a/pkg/fleetautoscalers/fleetautoscalers_test.go +++ b/pkg/fleetautoscalers/fleetautoscalers_test.go @@ -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, @@ -1208,7 +1207,7 @@ func TestApplyCounterPolicy(t *testing.T) { Capacity: 7, }}}}}, want: expected{ - replicas: 0, + replicas: 1, limited: true, wantErr: false, }, diff --git a/test/e2e/fleetautoscaler_test.go b/test/e2e/fleetautoscaler_test.go index 5c9619b078..75b3812cce 100644 --- a/test/e2e/fleetautoscaler_test.go +++ b/test/e2e/fleetautoscaler_test.go @@ -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", @@ -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))