Skip to content

Commit

Permalink
Set Minimum Buffer Size to 1 (#3749)
Browse files Browse the repository at this point in the history
* Set Minimums for DesiredCapacity and Buffer to 1

* fix lint

* Fix TestApplyListPolicy

* review changes

* Prevent scaling down to zero replicas in scaleDown logic

* modify TestApplyCounterPolicy

* remove number of replicas check

* modified scaleDown method and used helper function

* suggested changes

---------

Co-authored-by: Mark Mandel <[email protected]>
  • Loading branch information
Kalaiselvi84 and markmandel committed May 9, 2024
1 parent ae030c9 commit 8749377
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
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,
limited: true,
wantErr: false,
},
},
Expand Down

0 comments on commit 8749377

Please sign in to comment.