Commit b39cde37 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

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 -->
parents 4d9762e7 c5e82a01
...@@ -271,7 +271,10 @@ func (a *HorizontalController) reconcileAutoscaler(hpa *autoscaling.HorizontalPo ...@@ -271,7 +271,10 @@ func (a *HorizontalController) reconcileAutoscaler(hpa *autoscaling.HorizontalPo
rescaleReason := "" rescaleReason := ""
timestamp := time.Now() 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" rescaleReason = "Current number of replicas above Spec.MaxReplicas"
desiredReplicas = hpa.Spec.MaxReplicas desiredReplicas = hpa.Spec.MaxReplicas
} else if hpa.Spec.MinReplicas != nil && currentReplicas < *hpa.Spec.MinReplicas { } else if hpa.Spec.MinReplicas != nil && currentReplicas < *hpa.Spec.MinReplicas {
...@@ -323,7 +326,7 @@ func (a *HorizontalController) reconcileAutoscaler(hpa *autoscaling.HorizontalPo ...@@ -323,7 +326,7 @@ func (a *HorizontalController) reconcileAutoscaler(hpa *autoscaling.HorizontalPo
desiredReplicas = *hpa.Spec.MinReplicas desiredReplicas = *hpa.Spec.MinReplicas
} }
// TODO: remove when pod idling is done. // never scale down to 0, reserved for disabling autoscaling
if desiredReplicas == 0 { if desiredReplicas == 0 {
desiredReplicas = 1 desiredReplicas = 1
} }
......
...@@ -665,7 +665,7 @@ func TestZeroReplicas(t *testing.T) { ...@@ -665,7 +665,7 @@ func TestZeroReplicas(t *testing.T) {
minReplicas: 3, minReplicas: 3,
maxReplicas: 5, maxReplicas: 5,
initialReplicas: 0, initialReplicas: 0,
desiredReplicas: 3, desiredReplicas: 0,
CPUTarget: 90, CPUTarget: 90,
reportedLevels: []uint64{}, reportedLevels: []uint64{},
reportedCPURequests: []resource.Quantity{}, reportedCPURequests: []resource.Quantity{},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment