Skip to content

Commit 1d040a7

Browse files
authored
Merge pull request #516 from adrobisch/fix-enforce-boundaries-in-noop
autoscaler: enforce bounds when scaling hint is NONE
2 parents f716ae0 + 578cf14 commit 1d040a7

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

operator/autoscaler.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,16 @@ func (as *AutoScaler) scaleUpOrDown(esIndices map[string]ESIndex, scalingHint Sc
394394
Description: fmt.Sprintf("Decreasing node replicas to %d.", newDesiredNodeReplicas),
395395
}
396396
}
397+
398+
boundedNodeReplicas := as.ensureBoundsNodeReplicas(currentDesiredNodeReplicas)
399+
if boundedNodeReplicas != currentDesiredNodeReplicas {
400+
return &ScalingOperation{
401+
ScalingDirection: as.calculateScalingDirection(currentDesiredNodeReplicas, boundedNodeReplicas),
402+
NodeReplicas: &boundedNodeReplicas,
403+
Description: fmt.Sprintf("Adjusting node replicas to %d to fit MinReplicas/MaxReplicas bounds.", boundedNodeReplicas),
404+
}
405+
}
406+
397407
return noopScalingOperation("Nothing to do")
398408
}
399409

operator/autoscaler_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,34 @@ func TestScaleUpCausedByShardToNodeRatioExceeded(t *testing.T) {
367367
require.Equal(t, UP, actual.ScalingDirection, actual.Description)
368368
}
369369

370+
func TestEnsureMinMaxBoundsAppliedWhenScalingHintNoneAndNothingToDo(t *testing.T) {
371+
edS := edsTestFixture(4)
372+
edS.Spec.Scaling.MinReplicas = 6
373+
edS.Spec.Scaling.MaxReplicas = 6
374+
// allow 0 replicas to not trigger index-replica reconciliation
375+
edS.Spec.Scaling.MinIndexReplicas = 0
376+
377+
esNodes := make([]ESNode, 0)
378+
esIndices := map[string]ESIndex{
379+
"ad1": {Replicas: 0, Primaries: 4, Index: "ad1"},
380+
}
381+
382+
scalingHint := NONE
383+
384+
// with the given input:
385+
// - shard-to-node ratio is 4/4=1, which doesn't violate maxShardsPerNode
386+
// - index replicas are within configured bounds
387+
// - no scaling hint
388+
// this would be a noop operation but we still want
389+
// replica bounds (min/max replicas) to be enforced.
390+
as := systemUnderTest(edS, nil, nil)
391+
actual := as.calculateScalingOperation(esIndices, esNodes, scalingHint)
392+
393+
require.NotNil(t, actual.NodeReplicas)
394+
require.Equal(t, int32(6), *actual.NodeReplicas)
395+
require.Equal(t, UP, actual.ScalingDirection)
396+
}
397+
370398
func TestScaleUpCausedByShardToNodeRatioLessThanOne(t *testing.T) {
371399
eds := edsTestFixture(11)
372400
esNodes := make([]ESNode, 0)

0 commit comments

Comments
 (0)