Merge pull request #29212 from sjenning/hpa-idling

Automatic merge from submit-queue

HPA: ignore scale targets whose replica count is 0

Disable HPA when the user (or another component) explicitly sets the replicas to 0.

Fixes #28603

@kubernetes/autoscaling @fgrzadkowski @kubernetes/rh-cluster-infra @smarterclayton @ncdc

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.kubernetes.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.kubernetes.io/reviews/kubernetes/kubernetes/29212)
<!-- Reviewable:end -->
This commit is contained in:
Kubernetes Submit Queue 2016-08-09 10:44:56 -07:00 committed by GitHub
commit b39cde37c9
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{},