mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Merge pull request #21149 from mwielgus/hpa-rescale
Auto commit by PR queue bot
This commit is contained in:
commit
a6d855bf64
@ -161,7 +161,6 @@ func (a *HorizontalController) computeReplicasForCustomMetrics(hpa extensions.Ho
|
||||
}
|
||||
|
||||
return replicas, string(byteStatusList), timestamp, nil
|
||||
|
||||
}
|
||||
|
||||
func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodAutoscaler) error {
|
||||
@ -182,6 +181,18 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
|
||||
cmStatus := ""
|
||||
cmTimestamp := time.Time{}
|
||||
|
||||
desiredReplicas := 0
|
||||
timestamp := time.Now()
|
||||
|
||||
if currentReplicas > hpa.Spec.MaxReplicas {
|
||||
desiredReplicas = hpa.Spec.MaxReplicas
|
||||
} else if hpa.Spec.MinReplicas != nil && currentReplicas < *hpa.Spec.MinReplicas {
|
||||
desiredReplicas = *hpa.Spec.MinReplicas
|
||||
} else if currentReplicas == 0 {
|
||||
desiredReplicas = 1
|
||||
} else {
|
||||
// All basic scenarios covered, the state should be sane, lets use metrics.
|
||||
|
||||
if hpa.Spec.CPUUtilization != nil {
|
||||
cpuDesiredReplicas, cpuCurrentUtilization, cpuTimestamp, err = a.computeReplicasForCPUUtilization(hpa, scale)
|
||||
if err != nil {
|
||||
@ -198,9 +209,6 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
|
||||
}
|
||||
}
|
||||
|
||||
desiredReplicas := 0
|
||||
timestamp := time.Time{}
|
||||
|
||||
if cpuDesiredReplicas > desiredReplicas {
|
||||
desiredReplicas = cpuDesiredReplicas
|
||||
timestamp = cpuTimestamp
|
||||
@ -222,6 +230,7 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
|
||||
if desiredReplicas > hpa.Spec.MaxReplicas {
|
||||
desiredReplicas = hpa.Spec.MaxReplicas
|
||||
}
|
||||
}
|
||||
rescale := false
|
||||
|
||||
if desiredReplicas != currentReplicas {
|
||||
|
@ -333,6 +333,45 @@ func TestMinReplicas(t *testing.T) {
|
||||
tc.runTest(t)
|
||||
}
|
||||
|
||||
func TestZeroReplicas(t *testing.T) {
|
||||
tc := testCase{
|
||||
minReplicas: 3,
|
||||
maxReplicas: 5,
|
||||
initialReplicas: 0,
|
||||
desiredReplicas: 3,
|
||||
CPUTarget: 90,
|
||||
reportedLevels: []uint64{},
|
||||
reportedCPURequests: []resource.Quantity{},
|
||||
}
|
||||
tc.runTest(t)
|
||||
}
|
||||
|
||||
func TestToFewReplicas(t *testing.T) {
|
||||
tc := testCase{
|
||||
minReplicas: 3,
|
||||
maxReplicas: 5,
|
||||
initialReplicas: 2,
|
||||
desiredReplicas: 3,
|
||||
CPUTarget: 90,
|
||||
reportedLevels: []uint64{},
|
||||
reportedCPURequests: []resource.Quantity{},
|
||||
}
|
||||
tc.runTest(t)
|
||||
}
|
||||
|
||||
func TestTooManyReplicas(t *testing.T) {
|
||||
tc := testCase{
|
||||
minReplicas: 3,
|
||||
maxReplicas: 5,
|
||||
initialReplicas: 10,
|
||||
desiredReplicas: 5,
|
||||
CPUTarget: 90,
|
||||
reportedLevels: []uint64{},
|
||||
reportedCPURequests: []resource.Quantity{},
|
||||
}
|
||||
tc.runTest(t)
|
||||
}
|
||||
|
||||
func TestMaxReplicas(t *testing.T) {
|
||||
tc := testCase{
|
||||
minReplicas: 2,
|
||||
|
Loading…
Reference in New Issue
Block a user