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

hpa: Prevent scaling below MinReplicas if desiredReplicas is zero #48997

Merged
merged 1 commit into from Jul 17, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/controller/podautoscaler/horizontal.go
Expand Up @@ -450,14 +450,14 @@ func (a *HorizontalController) reconcileAutoscaler(hpav1Shared *autoscalingv1.Ho
case desiredReplicas > scaleUpLimit:
setCondition(hpa, autoscalingv2.ScalingLimited, v1.ConditionTrue, "ScaleUpLimit", "the desired replica count is increasing faster than the maximum scale rate")
desiredReplicas = scaleUpLimit
case desiredReplicas == 0:
// never scale down to 0, reserved for disabling autoscaling
setCondition(hpa, autoscalingv2.ScalingLimited, v1.ConditionTrue, "TooFewReplicas", "the desired replica count was zero")
desiredReplicas = 1
case hpa.Spec.MinReplicas != nil && desiredReplicas < *hpa.Spec.MinReplicas:
// make sure we aren't below our minimum
setCondition(hpa, autoscalingv2.ScalingLimited, v1.ConditionTrue, "TooFewReplicas", "the desired replica count was less than the minimum replica count")
desiredReplicas = *hpa.Spec.MinReplicas
case desiredReplicas == 0:
// never scale down to 0, reserved for disabling autoscaling
setCondition(hpa, autoscalingv2.ScalingLimited, v1.ConditionTrue, "TooFewReplicas", "the desired replica count was zero")
desiredReplicas = 1
case desiredReplicas > hpa.Spec.MaxReplicas:
// make sure we aren't above our maximum
setCondition(hpa, autoscalingv2.ScalingLimited, v1.ConditionTrue, "TooManyReplicas", "the desired replica count was more than the maximum replica count")
Expand Down
19 changes: 19 additions & 0 deletions pkg/controller/podautoscaler/horizontal_test.go
Expand Up @@ -994,6 +994,25 @@ func TestMinReplicas(t *testing.T) {
tc.runTest(t)
}

func TestMinReplicasDesiredZero(t *testing.T) {
tc := testCase{
minReplicas: 2,
maxReplicas: 5,
initialReplicas: 3,
desiredReplicas: 2,
CPUTarget: 90,
reportedLevels: []uint64{0, 0, 0},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")},
useMetricsApi: true,
expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{
Type: autoscalingv2.ScalingLimited,
Status: v1.ConditionTrue,
Reason: "TooFewReplicas",
}),
}
tc.runTest(t)
}

func TestZeroReplicas(t *testing.T) {
tc := testCase{
minReplicas: 3,
Expand Down