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

Set Minimum Buffer Size to 1 #3749

Merged
merged 15 commits into from
May 9, 2024
Merged
13 changes: 10 additions & 3 deletions pkg/fleetautoscalers/fleetautoscalers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ import (
"strings"
"time"

"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/uuid"

agonesv1 "agones.dev/agones/pkg/apis/agones/v1"
autoscalingv1 "agones.dev/agones/pkg/apis/autoscaling/v1"
listeragonesv1 "agones.dev/agones/pkg/client/listers/agones/v1"
"agones.dev/agones/pkg/fleets"
"agones.dev/agones/pkg/gameservers"
gssets "agones.dev/agones/pkg/gameserversets"
"agones.dev/agones/pkg/util/runtime"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/uuid"
)

var tlsConfig = &tls.Config{}
Expand Down Expand Up @@ -319,6 +320,12 @@ func applyCounterOrListPolicy(c *autoscalingv1.CounterPolicy, l *autoscalingv1.L
if err != nil {
return 0, false, err
}
// If the Aggregated Allocated Counts is 0 then desired capacity gets calculated as 0. If the
// capacity of 1 replica is equal to or greater than minimum capacity we can exit early.
if aggAllocatedCount <= 0 && capacity >= minCapacity {
return 1, true, nil
}

// The desired TOTAL capacity based on the Aggregated Allocated Counts (see applyBufferPolicy for explanation)
desiredCapacity := int64(math.Ceil(float64(aggAllocatedCount*100) / float64(100-bufferPercent)))
// Convert into a desired AVAILABLE capacity aka the buffer
Expand Down
15 changes: 8 additions & 7 deletions pkg/fleetautoscalers/fleetautoscalers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ import (
"net/http/httptest"
"testing"

agonesv1 "agones.dev/agones/pkg/apis/agones/v1"
autoscalingv1 "agones.dev/agones/pkg/apis/autoscaling/v1"
"agones.dev/agones/pkg/gameservers"
agtesting "agones.dev/agones/pkg/testing"
utilruntime "agones.dev/agones/pkg/util/runtime"
"github.com/stretchr/testify/assert"
admregv1 "k8s.io/api/admissionregistration/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
k8stesting "k8s.io/client-go/testing"

agonesv1 "agones.dev/agones/pkg/apis/agones/v1"
autoscalingv1 "agones.dev/agones/pkg/apis/autoscaling/v1"
"agones.dev/agones/pkg/gameservers"
agtesting "agones.dev/agones/pkg/testing"
utilruntime "agones.dev/agones/pkg/util/runtime"
)

const (
Expand Down Expand Up @@ -1950,8 +1951,8 @@ func TestApplyListPolicy(t *testing.T) {
}}}},
},
want: expected{
replicas: 0,
limited: false,
replicas: 1,
Kalaiselvi84 marked this conversation as resolved.
Show resolved Hide resolved
limited: true,
wantErr: false,
},
},
Expand Down
Loading