Merge pull request #89465 from shibataka000/84142-cm

Fix HPA bug about unintentional scale out during updating deployment when using PodMetric.
This commit is contained in:
Kubernetes Prow Robot 2020-12-16 04:44:21 -08:00 committed by GitHub
commit c5efee02ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -237,9 +237,15 @@ func (c *ReplicaCalculator) calcPlainMetricReplicas(metrics metricsclient.PodMet
return currentReplicas, utilization, nil return currentReplicas, utilization, nil
} }
newReplicas := int32(math.Ceil(newUsageRatio * float64(len(metrics))))
if (newUsageRatio < 1.0 && newReplicas > currentReplicas) || (newUsageRatio > 1.0 && newReplicas < currentReplicas) {
// return the current replicas if the change of metrics length would cause a change in scale direction
return currentReplicas, utilization, nil
}
// return the result, where the number of replicas considered is // return the result, where the number of replicas considered is
// however many replicas factored into our calculation // however many replicas factored into our calculation
return int32(math.Ceil(newUsageRatio * float64(len(metrics)))), utilization, nil return newReplicas, utilization, nil
} }
// GetObjectMetricReplicas calculates the desired replica count based on a target metric utilization (as a milli-value) // GetObjectMetricReplicas calculates the desired replica count based on a target metric utilization (as a milli-value)

View File

@ -1481,6 +1481,22 @@ func TestReplicaCalcDuringRollingUpdateWithMaxSurge(t *testing.T) {
tc.runTest(t) tc.runTest(t)
} }
func TestReplicaCalcDuringRollingUpdateWithMaxSurgeCM(t *testing.T) {
tc := replicaCalcTestCase{
currentReplicas: 2,
expectedReplicas: 2,
podPhase: []v1.PodPhase{v1.PodRunning, v1.PodRunning, v1.PodRunning},
metric: &metricInfo{
name: "qps",
levels: []int64{10000, 10000},
targetUtilization: 17000,
expectedUtilization: 10000,
metricType: podMetric,
},
}
tc.runTest(t)
}
// TestComputedToleranceAlgImplementation is a regression test which // TestComputedToleranceAlgImplementation is a regression test which
// back-calculates a minimal percentage for downscaling based on a small percentage // back-calculates a minimal percentage for downscaling based on a small percentage
// increase in pod utilization which is calibrated against the tolerance value. // increase in pod utilization which is calibrated against the tolerance value.