From eb58831990ba80f37f45597391321be6f5294b1a Mon Sep 17 00:00:00 2001 From: Antanas Bastys Date: Tue, 15 Mar 2022 10:15:32 +0200 Subject: [PATCH] prevent scaling down to 0 instances --- pkg/controller/update_cluster.go | 4 ++-- pkg/controller/update_cluster_test.go | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/pkg/controller/update_cluster.go b/pkg/controller/update_cluster.go index 142af92..5192aee 100644 --- a/pkg/controller/update_cluster.go +++ b/pkg/controller/update_cluster.go @@ -590,8 +590,8 @@ func (c *M3DBController) findPodsAndInstancesToRemove( if len(pods) == 0 { return nil, nil, errEmptyPodList } - if desiredInstanceCount < 0 { - msg := fmt.Sprintf("desired instance count is negative: %d", desiredInstanceCount) + if desiredInstanceCount <= 0 { + msg := fmt.Sprintf("desired instance count should be positive, but is: %d", desiredInstanceCount) return nil, nil, pkgerrors.New(msg) } diff --git a/pkg/controller/update_cluster_test.go b/pkg/controller/update_cluster_test.go index b1840dd..a320548 100644 --- a/pkg/controller/update_cluster_test.go +++ b/pkg/controller/update_cluster_test.go @@ -715,20 +715,16 @@ func TestShrinkPlacementForSet(t *testing.T) { expectedRemovedIds: []string{`{"name":"cluster-zones-rep0-1","uid":"1"}`}, }, { - name: "remove more pods than exists", + name: "negative desired instance count", desiredInstanceCount: -42, placementInstanceCount: instanceCountPerGroup, - expectedErr: "desired instance count is negative: -42", + expectedErr: "desired instance count should be positive, but is: -42", }, { - name: "remove all pods", + name: "0 desired instances", desiredInstanceCount: 0, placementInstanceCount: instanceCountPerGroup, - expectedRemovedIds: []string{ - `{"name":"cluster-zones-rep0-2","uid":"2"}`, - `{"name":"cluster-zones-rep0-1","uid":"1"}`, - `{"name":"cluster-zones-rep0-0","uid":"0"}`, - }, + expectedErr: "desired instance count should be positive, but is: 0", }, { name: "prevent scale down",