Merge pull request #112178 from kushagra98/hpa-scale-down

FIX: HPAs scale down with target >= 100
This commit is contained in:
Kubernetes Prow Robot 2022-09-14 11:09:13 -07:00 committed by GitHub
commit 03d688c4b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -105,9 +105,11 @@ func (c *ReplicaCalculator) GetResourceReplicas(ctx context.Context, currentRepl
if len(missingPods) > 0 {
if usageRatio < 1.0 {
// on a scale-down, treat missing pods as using 100% of the resource request
// on a scale-down, treat missing pods as using 100% (all) of the resource request
// or the utilization target for targets higher than 100%
fallbackUtilization := int64(max(100, targetUtilization))
for podName := range missingPods {
metrics[podName] = metricsclient.PodMetric{Value: requests[podName]}
metrics[podName] = metricsclient.PodMetric{Value: requests[podName] * fallbackUtilization / 100}
}
} else if usageRatio > 1.0 {
// on a scale-up, treat missing pods as using 0% of the resource request
@ -208,7 +210,7 @@ func (c *ReplicaCalculator) calcPlainMetricReplicas(metrics metricsclient.PodMet
if len(missingPods) > 0 {
if usageRatio < 1.0 {
// on a scale-down, treat missing pods as using 100% of the resource request
// on a scale-down, treat missing pods as using exactly the target amount
for podName := range missingPods {
metrics[podName] = metricsclient.PodMetric{Value: targetUtilization}
}

View File

@ -1464,6 +1464,24 @@ func TestReplicaCalcMissingMetricsUnreadyScaleDown(t *testing.T) {
tc.runTest(t)
}
func TestReplicaCalcMissingMetricsScaleDownTargetOver100(t *testing.T) {
tc := replicaCalcTestCase{
currentReplicas: 4,
expectedReplicas: 2,
podReadiness: []v1.ConditionStatus{v1.ConditionFalse, v1.ConditionTrue, v1.ConditionTrue, v1.ConditionTrue},
resource: &resourceInfo{
name: v1.ResourceCPU,
requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("2.0"), resource.MustParse("2.0")},
levels: makePodMetricLevels(200, 100, 100),
targetUtilization: 300,
expectedUtilization: 6,
expectedValue: numContainersPerPod * 100,
},
}
tc.runTest(t)
}
func TestReplicaCalcDuringRollingUpdateWithMaxSurge(t *testing.T) {
tc := replicaCalcTestCase{
currentReplicas: 2,