Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions operator/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,16 @@ func (as *AutoScaler) scaleUpOrDown(esIndices map[string]ESIndex, scalingHint Sc
Description: fmt.Sprintf("Decreasing node replicas to %d.", newDesiredNodeReplicas),
}
}

boundedNodeReplicas := as.ensureBoundsNodeReplicas(currentDesiredNodeReplicas)
if boundedNodeReplicas != currentDesiredNodeReplicas {
return &ScalingOperation{
ScalingDirection: as.calculateScalingDirection(currentDesiredNodeReplicas, boundedNodeReplicas),
NodeReplicas: &boundedNodeReplicas,
Description: fmt.Sprintf("Adjusting node replicas to %d to fit MinReplicas/MaxReplicas bounds.", boundedNodeReplicas),
}
}

return noopScalingOperation("Nothing to do")
}

Expand Down
28 changes: 28 additions & 0 deletions operator/autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,34 @@ func TestScaleUpCausedByShardToNodeRatioExceeded(t *testing.T) {
require.Equal(t, UP, actual.ScalingDirection, actual.Description)
}

func TestEnsureMinMaxBoundsAppliedWhenScalingHintNoneAndNothingToDo(t *testing.T) {
edS := edsTestFixture(4)
edS.Spec.Scaling.MinReplicas = 6
edS.Spec.Scaling.MaxReplicas = 6
// allow 0 replicas to not trigger index-replica reconciliation
edS.Spec.Scaling.MinIndexReplicas = 0

esNodes := make([]ESNode, 0)
esIndices := map[string]ESIndex{
"ad1": {Replicas: 0, Primaries: 4, Index: "ad1"},
}

scalingHint := NONE

// with the given input:
// - shard-to-node ratio is 4/4=1, which doesn't violate maxShardsPerNode
// - index replicas are within configured bounds
// - no scaling hint
// this would be a noop operation but we still want
// replica bounds (min/max replicas) to be enforced.
as := systemUnderTest(edS, nil, nil)
actual := as.calculateScalingOperation(esIndices, esNodes, scalingHint)

require.NotNil(t, actual.NodeReplicas)
require.Equal(t, int32(6), *actual.NodeReplicas)
require.Equal(t, UP, actual.ScalingDirection)
}

func TestScaleUpCausedByShardToNodeRatioLessThanOne(t *testing.T) {
eds := edsTestFixture(11)
esNodes := make([]ESNode, 0)
Expand Down
Loading