Merge pull request #78725 from waynepeking348/waynepeking348-master

fix bug of replica_calculator to initialize replicaCount with currentReplicas
This commit is contained in:
Kubernetes Prow Robot 2019-06-06 10:48:27 -07:00 committed by GitHub
commit 602fc4771a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -265,6 +265,7 @@ func (c *ReplicaCalculator) GetObjectPerPodMetricReplicas(currentReplicas int32,
return 0, 0, time.Time{}, fmt.Errorf("unable to get metric %s: %v on %s %s/%s", metricName, objectRef.Kind, namespace, objectRef.Name, err) return 0, 0, time.Time{}, fmt.Errorf("unable to get metric %s: %v on %s %s/%s", metricName, objectRef.Kind, namespace, objectRef.Name, err)
} }
replicaCount = currentReplicas
usageRatio := float64(utilization) / (float64(targetAverageUtilization) * float64(replicaCount)) usageRatio := float64(utilization) / (float64(targetAverageUtilization) * float64(replicaCount))
if math.Abs(1.0-usageRatio) > c.tolerance { if math.Abs(1.0-usageRatio) > c.tolerance {
// update number of replicas if change is large enough // update number of replicas if change is large enough

View File

@ -970,6 +970,26 @@ func TestReplicaCalcToleranceCMObject(t *testing.T) {
tc.runTest(t) tc.runTest(t)
} }
func TestReplicaCalcTolerancePerPodCMObject(t *testing.T) {
tc := replicaCalcTestCase{
currentReplicas: 4,
expectedReplicas: 4,
metric: &metricInfo{
metricType: objectPerPodMetric,
name: "qps",
levels: []int64{20166},
perPodTargetUtilization: 5000,
expectedUtilization: 5042,
singleObject: &autoscalingv2.CrossVersionObjectReference{
Kind: "Deployment",
APIVersion: "apps/v1",
Name: "some-deployment",
},
},
}
tc.runTest(t)
}
func TestReplicaCalcToleranceCMExternal(t *testing.T) { func TestReplicaCalcToleranceCMExternal(t *testing.T) {
tc := replicaCalcTestCase{ tc := replicaCalcTestCase{
currentReplicas: 3, currentReplicas: 3,