hpa: ignore scale targets whose replica count is 0

This commit is contained in:
Seth Jennings 2016-07-19 10:54:38 -05:00
parent 73a3d48dc8
commit c5e82a01b1
2 changed files with 6 additions and 3 deletions

View File

@ -271,7 +271,10 @@ func (a *HorizontalController) reconcileAutoscaler(hpa *autoscaling.HorizontalPo
rescaleReason := ""
timestamp := time.Now()
if currentReplicas > hpa.Spec.MaxReplicas {
if scale.Spec.Replicas == 0 {
// Autoscaling is disabled for this resource
desiredReplicas = 0
} else if currentReplicas > hpa.Spec.MaxReplicas {
rescaleReason = "Current number of replicas above Spec.MaxReplicas"
desiredReplicas = hpa.Spec.MaxReplicas
} else if hpa.Spec.MinReplicas != nil && currentReplicas < *hpa.Spec.MinReplicas {
@ -323,7 +326,7 @@ func (a *HorizontalController) reconcileAutoscaler(hpa *autoscaling.HorizontalPo
desiredReplicas = *hpa.Spec.MinReplicas
}
// TODO: remove when pod idling is done.
// never scale down to 0, reserved for disabling autoscaling
if desiredReplicas == 0 {
desiredReplicas = 1
}

View File

@ -665,7 +665,7 @@ func TestZeroReplicas(t *testing.T) {
minReplicas: 3,
maxReplicas: 5,
initialReplicas: 0,
desiredReplicas: 3,
desiredReplicas: 0,
CPUTarget: 90,
reportedLevels: []uint64{},
reportedCPURequests: []resource.Quantity{},