Commit 7d0977d8 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #52238 from…

Merge pull request #52238 from mattjmcnaughton/mattjmcnaughton/address-golint-errors-in-podautoscaler Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix golint errors in `pkg/controller/podautoscaler` **What this PR does / why we need it**: Address `golint` errors in `pkg/controller/podautoscaler`. Note, I did not address issues around exported types/functions missing comments, because I'm not sure what the convention within the k8s project is. ```release-note NONE ``` Signed-off-by: 's avatarmattjmcnaughton <mattjmcnaughton@gmail.com>
parents e1d923a7 ff6fa927
...@@ -106,7 +106,7 @@ type testCase struct { ...@@ -106,7 +106,7 @@ type testCase struct {
statusUpdated bool statusUpdated bool
eventCreated bool eventCreated bool
verifyEvents bool verifyEvents bool
useMetricsApi bool useMetricsAPI bool
metricsTarget []autoscalingv2.MetricSpec metricsTarget []autoscalingv2.MetricSpec
expectedConditions []autoscalingv1.HorizontalPodAutoscalerCondition expectedConditions []autoscalingv1.HorizontalPodAutoscalerCondition
// Channel with names of HPA objects which we have reconciled. // Channel with names of HPA objects which we have reconciled.
...@@ -483,44 +483,44 @@ func (tc *testCase) prepareTestClient(t *testing.T) (*fake.Clientset, *metricsfa ...@@ -483,44 +483,44 @@ func (tc *testCase) prepareTestClient(t *testing.T) (*fake.Clientset, *metricsfa
} }
return true, metrics, nil return true, metrics, nil
} else { }
name := getForAction.GetName()
mapper := api.Registry.RESTMapper() name := getForAction.GetName()
metrics := &cmapi.MetricValueList{} mapper := api.Registry.RESTMapper()
var matchedTarget *autoscalingv2.MetricSpec metrics := &cmapi.MetricValueList{}
for i, target := range tc.metricsTarget { var matchedTarget *autoscalingv2.MetricSpec
if target.Type == autoscalingv2.ObjectMetricSourceType && name == target.Object.Target.Name { for i, target := range tc.metricsTarget {
gk := schema.FromAPIVersionAndKind(target.Object.Target.APIVersion, target.Object.Target.Kind).GroupKind() if target.Type == autoscalingv2.ObjectMetricSourceType && name == target.Object.Target.Name {
mapping, err := mapper.RESTMapping(gk) gk := schema.FromAPIVersionAndKind(target.Object.Target.APIVersion, target.Object.Target.Kind).GroupKind()
if err != nil { mapping, err := mapper.RESTMapping(gk)
t.Logf("unable to get mapping for %s: %v", gk.String(), err) if err != nil {
continue t.Logf("unable to get mapping for %s: %v", gk.String(), err)
} continue
groupResource := schema.GroupResource{Group: mapping.GroupVersionKind.Group, Resource: mapping.Resource}
if getForAction.GetResource().Resource == groupResource.String() {
matchedTarget = &tc.metricsTarget[i]
}
} }
} groupResource := schema.GroupResource{Group: mapping.GroupVersionKind.Group, Resource: mapping.Resource}
assert.NotNil(t, matchedTarget, "this request should have matched one of the metric specs")
assert.Equal(t, "qps", getForAction.GetMetricName(), "the metric name requested should have been qps, as specified in the metric spec")
metrics.Items = []cmapi.MetricValue{ if getForAction.GetResource().Resource == groupResource.String() {
{ matchedTarget = &tc.metricsTarget[i]
DescribedObject: v1.ObjectReference{ }
Kind: matchedTarget.Object.Target.Kind,
APIVersion: matchedTarget.Object.Target.APIVersion,
Name: name,
},
Timestamp: metav1.Time{Time: time.Now()},
MetricName: "qps",
Value: *resource.NewMilliQuantity(int64(tc.reportedLevels[0]), resource.DecimalSI),
},
} }
}
assert.NotNil(t, matchedTarget, "this request should have matched one of the metric specs")
assert.Equal(t, "qps", getForAction.GetMetricName(), "the metric name requested should have been qps, as specified in the metric spec")
return true, metrics, nil metrics.Items = []cmapi.MetricValue{
{
DescribedObject: v1.ObjectReference{
Kind: matchedTarget.Object.Target.Kind,
APIVersion: matchedTarget.Object.Target.APIVersion,
Name: name,
},
Timestamp: metav1.Time{Time: time.Now()},
MetricName: "qps",
Value: *resource.NewMilliQuantity(int64(tc.reportedLevels[0]), resource.DecimalSI),
},
} }
return true, metrics, nil
}) })
return fakeClient, fakeMetricsClient, fakeCMClient return fakeClient, fakeMetricsClient, fakeCMClient
...@@ -634,7 +634,7 @@ func TestScaleUp(t *testing.T) { ...@@ -634,7 +634,7 @@ func TestScaleUp(t *testing.T) {
verifyCPUCurrent: true, verifyCPUCurrent: true,
reportedLevels: []uint64{300, 500, 700}, reportedLevels: []uint64{300, 500, 700},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -651,7 +651,7 @@ func TestScaleUpUnreadyLessScale(t *testing.T) { ...@@ -651,7 +651,7 @@ func TestScaleUpUnreadyLessScale(t *testing.T) {
reportedLevels: []uint64{300, 500, 700}, reportedLevels: []uint64{300, 500, 700},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
reportedPodReadiness: []v1.ConditionStatus{v1.ConditionFalse, v1.ConditionTrue, v1.ConditionTrue}, reportedPodReadiness: []v1.ConditionStatus{v1.ConditionFalse, v1.ConditionTrue, v1.ConditionTrue},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -668,7 +668,7 @@ func TestScaleUpUnreadyNoScale(t *testing.T) { ...@@ -668,7 +668,7 @@ func TestScaleUpUnreadyNoScale(t *testing.T) {
reportedLevels: []uint64{400, 500, 700}, reportedLevels: []uint64{400, 500, 700},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
reportedPodReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse}, reportedPodReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{ expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{
Type: autoscalingv2.AbleToScale, Type: autoscalingv2.AbleToScale,
Status: v1.ConditionTrue, Status: v1.ConditionTrue,
...@@ -688,7 +688,7 @@ func TestScaleUpDeployment(t *testing.T) { ...@@ -688,7 +688,7 @@ func TestScaleUpDeployment(t *testing.T) {
verifyCPUCurrent: true, verifyCPUCurrent: true,
reportedLevels: []uint64{300, 500, 700}, reportedLevels: []uint64{300, 500, 700},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
resource: &fakeResource{ resource: &fakeResource{
name: "test-dep", name: "test-dep",
apiVersion: "extensions/v1beta1", apiVersion: "extensions/v1beta1",
...@@ -708,7 +708,7 @@ func TestScaleUpReplicaSet(t *testing.T) { ...@@ -708,7 +708,7 @@ func TestScaleUpReplicaSet(t *testing.T) {
verifyCPUCurrent: true, verifyCPUCurrent: true,
reportedLevels: []uint64{300, 500, 700}, reportedLevels: []uint64{300, 500, 700},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
resource: &fakeResource{ resource: &fakeResource{
name: "test-replicaset", name: "test-replicaset",
apiVersion: "extensions/v1beta1", apiVersion: "extensions/v1beta1",
...@@ -827,7 +827,7 @@ func TestScaleDown(t *testing.T) { ...@@ -827,7 +827,7 @@ func TestScaleDown(t *testing.T) {
verifyCPUCurrent: true, verifyCPUCurrent: true,
reportedLevels: []uint64{100, 300, 500, 250, 250}, reportedLevels: []uint64{100, 300, 500, 250, 250},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -892,7 +892,7 @@ func TestScaleDownIgnoresUnreadyPods(t *testing.T) { ...@@ -892,7 +892,7 @@ func TestScaleDownIgnoresUnreadyPods(t *testing.T) {
verifyCPUCurrent: true, verifyCPUCurrent: true,
reportedLevels: []uint64{100, 300, 500, 250, 250}, reportedLevels: []uint64{100, 300, 500, 250, 250},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
reportedPodReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionTrue, v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse}, reportedPodReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionTrue, v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse},
} }
tc.runTest(t) tc.runTest(t)
...@@ -907,7 +907,7 @@ func TestTolerance(t *testing.T) { ...@@ -907,7 +907,7 @@ func TestTolerance(t *testing.T) {
CPUTarget: 100, CPUTarget: 100,
reportedLevels: []uint64{1010, 1030, 1020}, reportedLevels: []uint64{1010, 1030, 1020},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{ expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{
Type: autoscalingv2.AbleToScale, Type: autoscalingv2.AbleToScale,
Status: v1.ConditionTrue, Status: v1.ConditionTrue,
...@@ -983,7 +983,7 @@ func TestMinReplicas(t *testing.T) { ...@@ -983,7 +983,7 @@ func TestMinReplicas(t *testing.T) {
CPUTarget: 90, CPUTarget: 90,
reportedLevels: []uint64{10, 95, 10}, reportedLevels: []uint64{10, 95, 10},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{ expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{
Type: autoscalingv2.ScalingLimited, Type: autoscalingv2.ScalingLimited,
Status: v1.ConditionTrue, Status: v1.ConditionTrue,
...@@ -1002,7 +1002,7 @@ func TestMinReplicasDesiredZero(t *testing.T) { ...@@ -1002,7 +1002,7 @@ func TestMinReplicasDesiredZero(t *testing.T) {
CPUTarget: 90, CPUTarget: 90,
reportedLevels: []uint64{0, 0, 0}, reportedLevels: []uint64{0, 0, 0},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{ expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{
Type: autoscalingv2.ScalingLimited, Type: autoscalingv2.ScalingLimited,
Status: v1.ConditionTrue, Status: v1.ConditionTrue,
...@@ -1021,7 +1021,7 @@ func TestZeroReplicas(t *testing.T) { ...@@ -1021,7 +1021,7 @@ func TestZeroReplicas(t *testing.T) {
CPUTarget: 90, CPUTarget: 90,
reportedLevels: []uint64{}, reportedLevels: []uint64{},
reportedCPURequests: []resource.Quantity{}, reportedCPURequests: []resource.Quantity{},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{ expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{
{Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededGetScale"}, {Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededGetScale"},
{Type: autoscalingv1.ScalingActive, Status: v1.ConditionFalse, Reason: "ScalingDisabled"}, {Type: autoscalingv1.ScalingActive, Status: v1.ConditionFalse, Reason: "ScalingDisabled"},
...@@ -1039,7 +1039,7 @@ func TestTooFewReplicas(t *testing.T) { ...@@ -1039,7 +1039,7 @@ func TestTooFewReplicas(t *testing.T) {
CPUTarget: 90, CPUTarget: 90,
reportedLevels: []uint64{}, reportedLevels: []uint64{},
reportedCPURequests: []resource.Quantity{}, reportedCPURequests: []resource.Quantity{},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{ expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{
{Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededRescale"}, {Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededRescale"},
}, },
...@@ -1056,7 +1056,7 @@ func TestTooManyReplicas(t *testing.T) { ...@@ -1056,7 +1056,7 @@ func TestTooManyReplicas(t *testing.T) {
CPUTarget: 90, CPUTarget: 90,
reportedLevels: []uint64{}, reportedLevels: []uint64{},
reportedCPURequests: []resource.Quantity{}, reportedCPURequests: []resource.Quantity{},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{ expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{
{Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededRescale"}, {Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededRescale"},
}, },
...@@ -1073,7 +1073,7 @@ func TestMaxReplicas(t *testing.T) { ...@@ -1073,7 +1073,7 @@ func TestMaxReplicas(t *testing.T) {
CPUTarget: 90, CPUTarget: 90,
reportedLevels: []uint64{8000, 9500, 1000}, reportedLevels: []uint64{8000, 9500, 1000},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{ expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{
Type: autoscalingv2.ScalingLimited, Type: autoscalingv2.ScalingLimited,
Status: v1.ConditionTrue, Status: v1.ConditionTrue,
...@@ -1092,7 +1092,7 @@ func TestSuperfluousMetrics(t *testing.T) { ...@@ -1092,7 +1092,7 @@ func TestSuperfluousMetrics(t *testing.T) {
CPUTarget: 100, CPUTarget: 100,
reportedLevels: []uint64{4000, 9500, 3000, 7000, 3200, 2000}, reportedLevels: []uint64{4000, 9500, 3000, 7000, 3200, 2000},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{ expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{
Type: autoscalingv2.ScalingLimited, Type: autoscalingv2.ScalingLimited,
Status: v1.ConditionTrue, Status: v1.ConditionTrue,
...@@ -1111,7 +1111,7 @@ func TestMissingMetrics(t *testing.T) { ...@@ -1111,7 +1111,7 @@ func TestMissingMetrics(t *testing.T) {
CPUTarget: 100, CPUTarget: 100,
reportedLevels: []uint64{400, 95}, reportedLevels: []uint64{400, 95},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -1125,7 +1125,7 @@ func TestEmptyMetrics(t *testing.T) { ...@@ -1125,7 +1125,7 @@ func TestEmptyMetrics(t *testing.T) {
CPUTarget: 100, CPUTarget: 100,
reportedLevels: []uint64{}, reportedLevels: []uint64{},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{ expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{
{Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededGetScale"}, {Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededGetScale"},
{Type: autoscalingv1.ScalingActive, Status: v1.ConditionFalse, Reason: "FailedGetResourceMetric"}, {Type: autoscalingv1.ScalingActive, Status: v1.ConditionFalse, Reason: "FailedGetResourceMetric"},
...@@ -1142,7 +1142,7 @@ func TestEmptyCPURequest(t *testing.T) { ...@@ -1142,7 +1142,7 @@ func TestEmptyCPURequest(t *testing.T) {
desiredReplicas: 1, desiredReplicas: 1,
CPUTarget: 100, CPUTarget: 100,
reportedLevels: []uint64{200}, reportedLevels: []uint64{200},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{ expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{
{Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededGetScale"}, {Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededGetScale"},
{Type: autoscalingv1.ScalingActive, Status: v1.ConditionFalse, Reason: "FailedGetResourceMetric"}, {Type: autoscalingv1.ScalingActive, Status: v1.ConditionFalse, Reason: "FailedGetResourceMetric"},
...@@ -1161,7 +1161,7 @@ func TestEventCreated(t *testing.T) { ...@@ -1161,7 +1161,7 @@ func TestEventCreated(t *testing.T) {
reportedLevels: []uint64{200}, reportedLevels: []uint64{200},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.2")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.2")},
verifyEvents: true, verifyEvents: true,
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -1176,7 +1176,7 @@ func TestEventNotCreated(t *testing.T) { ...@@ -1176,7 +1176,7 @@ func TestEventNotCreated(t *testing.T) {
reportedLevels: []uint64{200, 200}, reportedLevels: []uint64{200, 200},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.4"), resource.MustParse("0.4")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.4"), resource.MustParse("0.4")},
verifyEvents: true, verifyEvents: true,
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{ expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{
Type: autoscalingv2.AbleToScale, Type: autoscalingv2.AbleToScale,
Status: v1.ConditionTrue, Status: v1.ConditionTrue,
...@@ -1195,7 +1195,7 @@ func TestMissingReports(t *testing.T) { ...@@ -1195,7 +1195,7 @@ func TestMissingReports(t *testing.T) {
CPUTarget: 50, CPUTarget: 50,
reportedLevels: []uint64{200}, reportedLevels: []uint64{200},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.2")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.2")},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -1209,7 +1209,7 @@ func TestUpscaleCap(t *testing.T) { ...@@ -1209,7 +1209,7 @@ func TestUpscaleCap(t *testing.T) {
CPUTarget: 10, CPUTarget: 10,
reportedLevels: []uint64{100, 200, 300}, reportedLevels: []uint64{100, 200, 300},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{ expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{
Type: autoscalingv2.ScalingLimited, Type: autoscalingv2.ScalingLimited,
Status: v1.ConditionTrue, Status: v1.ConditionTrue,
...@@ -1228,7 +1228,7 @@ func TestConditionInvalidSelectorMissing(t *testing.T) { ...@@ -1228,7 +1228,7 @@ func TestConditionInvalidSelectorMissing(t *testing.T) {
CPUTarget: 10, CPUTarget: 10,
reportedLevels: []uint64{100, 200, 300}, reportedLevels: []uint64{100, 200, 300},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{ expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{
{ {
Type: autoscalingv1.AbleToScale, Type: autoscalingv1.AbleToScale,
...@@ -1273,7 +1273,7 @@ func TestConditionInvalidSelectorUnparsable(t *testing.T) { ...@@ -1273,7 +1273,7 @@ func TestConditionInvalidSelectorUnparsable(t *testing.T) {
CPUTarget: 10, CPUTarget: 10,
reportedLevels: []uint64{100, 200, 300}, reportedLevels: []uint64{100, 200, 300},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{ expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{
{ {
Type: autoscalingv1.AbleToScale, Type: autoscalingv1.AbleToScale,
...@@ -1347,17 +1347,17 @@ func TestConditionFailedGetMetrics(t *testing.T) { ...@@ -1347,17 +1347,17 @@ func TestConditionFailedGetMetrics(t *testing.T) {
CPUTarget: 10, CPUTarget: 10,
reportedLevels: []uint64{100, 200, 300}, reportedLevels: []uint64{100, 200, 300},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")},
useMetricsApi: true, useMetricsAPI: true,
} }
_, testMetricsClient, testCMClient := tc.prepareTestClient(t) _, testMetricsClient, testCMClient := tc.prepareTestClient(t)
tc.testMetricsClient = testMetricsClient tc.testMetricsClient = testMetricsClient
tc.testCMClient = testCMClient tc.testCMClient = testCMClient
testMetricsClient.PrependReactor("list", "pods", func(action core.Action) (handled bool, ret runtime.Object, err error) { testMetricsClient.PrependReactor("list", "pods", func(action core.Action) (handled bool, ret runtime.Object, err error) {
return true, &metricsapi.PodMetricsList{}, fmt.Errorf("something went wrong!") return true, &metricsapi.PodMetricsList{}, fmt.Errorf("something went wrong")
}) })
testCMClient.PrependReactor("get", "*", func(action core.Action) (handled bool, ret runtime.Object, err error) { testCMClient.PrependReactor("get", "*", func(action core.Action) (handled bool, ret runtime.Object, err error) {
return true, &cmapi.MetricValueList{}, fmt.Errorf("something went wrong!") return true, &cmapi.MetricValueList{}, fmt.Errorf("something went wrong")
}) })
tc.expectedConditions = []autoscalingv1.HorizontalPodAutoscalerCondition{ tc.expectedConditions = []autoscalingv1.HorizontalPodAutoscalerCondition{
...@@ -1412,7 +1412,7 @@ func TestConditionFailedGetScale(t *testing.T) { ...@@ -1412,7 +1412,7 @@ func TestConditionFailedGetScale(t *testing.T) {
CPUTarget: 10, CPUTarget: 10,
reportedLevels: []uint64{100, 200, 300}, reportedLevels: []uint64{100, 200, 300},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{ expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{
{ {
Type: autoscalingv1.AbleToScale, Type: autoscalingv1.AbleToScale,
...@@ -1426,7 +1426,7 @@ func TestConditionFailedGetScale(t *testing.T) { ...@@ -1426,7 +1426,7 @@ func TestConditionFailedGetScale(t *testing.T) {
tc.testClient = testClient tc.testClient = testClient
testClient.PrependReactor("get", "replicationcontrollers", func(action core.Action) (handled bool, ret runtime.Object, err error) { testClient.PrependReactor("get", "replicationcontrollers", func(action core.Action) (handled bool, ret runtime.Object, err error) {
return true, &extensions.Scale{}, fmt.Errorf("something went wrong!") return true, &extensions.Scale{}, fmt.Errorf("something went wrong")
}) })
tc.runTest(t) tc.runTest(t)
...@@ -1441,7 +1441,7 @@ func TestConditionFailedUpdateScale(t *testing.T) { ...@@ -1441,7 +1441,7 @@ func TestConditionFailedUpdateScale(t *testing.T) {
CPUTarget: 100, CPUTarget: 100,
reportedLevels: []uint64{150, 150, 150}, reportedLevels: []uint64{150, 150, 150},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")},
useMetricsApi: true, useMetricsAPI: true,
expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{ expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{
Type: autoscalingv2.AbleToScale, Type: autoscalingv2.AbleToScale,
Status: v1.ConditionFalse, Status: v1.ConditionFalse,
...@@ -1453,7 +1453,7 @@ func TestConditionFailedUpdateScale(t *testing.T) { ...@@ -1453,7 +1453,7 @@ func TestConditionFailedUpdateScale(t *testing.T) {
tc.testClient = testClient tc.testClient = testClient
testClient.PrependReactor("update", "replicationcontrollers", func(action core.Action) (handled bool, ret runtime.Object, err error) { testClient.PrependReactor("update", "replicationcontrollers", func(action core.Action) (handled bool, ret runtime.Object, err error) {
return true, &extensions.Scale{}, fmt.Errorf("something went wrong!") return true, &extensions.Scale{}, fmt.Errorf("something went wrong")
}) })
tc.runTest(t) tc.runTest(t)
...@@ -1469,7 +1469,7 @@ func TestBackoffUpscale(t *testing.T) { ...@@ -1469,7 +1469,7 @@ func TestBackoffUpscale(t *testing.T) {
CPUTarget: 100, CPUTarget: 100,
reportedLevels: []uint64{150, 150, 150}, reportedLevels: []uint64{150, 150, 150},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")},
useMetricsApi: true, useMetricsAPI: true,
lastScaleTime: &time, lastScaleTime: &time,
expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{ expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{
Type: autoscalingv2.AbleToScale, Type: autoscalingv2.AbleToScale,
...@@ -1494,7 +1494,7 @@ func TestBackoffDownscale(t *testing.T) { ...@@ -1494,7 +1494,7 @@ func TestBackoffDownscale(t *testing.T) {
CPUTarget: 100, CPUTarget: 100,
reportedLevels: []uint64{50, 50, 50}, reportedLevels: []uint64{50, 50, 50},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")},
useMetricsApi: true, useMetricsAPI: true,
lastScaleTime: &time, lastScaleTime: &time,
expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{ expectedConditions: statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{
Type: autoscalingv2.AbleToScale, Type: autoscalingv2.AbleToScale,
...@@ -1526,7 +1526,7 @@ func TestComputedToleranceAlgImplementation(t *testing.T) { ...@@ -1526,7 +1526,7 @@ func TestComputedToleranceAlgImplementation(t *testing.T) {
// Force a minimal scaling event by satisfying (tolerance < 1 - resourcesUsedRatio). // Force a minimal scaling event by satisfying (tolerance < 1 - resourcesUsedRatio).
target := math.Abs(1/(requestedToUsed*(1-tolerance))) + .01 target := math.Abs(1/(requestedToUsed*(1-tolerance))) + .01
finalCpuPercentTarget := int32(target * 100) finalCPUPercentTarget := int32(target * 100)
resourcesUsedRatio := float64(totalUsedCPUOfAllPods) / float64(float64(totalRequestedCPUOfAllPods)*target) resourcesUsedRatio := float64(totalUsedCPUOfAllPods) / float64(float64(totalRequestedCPUOfAllPods)*target)
// i.e. .60 * 20 -> scaled down expectation. // i.e. .60 * 20 -> scaled down expectation.
...@@ -1538,7 +1538,7 @@ func TestComputedToleranceAlgImplementation(t *testing.T) { ...@@ -1538,7 +1538,7 @@ func TestComputedToleranceAlgImplementation(t *testing.T) {
maxReplicas: 1000, maxReplicas: 1000,
initialReplicas: startPods, initialReplicas: startPods,
desiredReplicas: finalPods, desiredReplicas: finalPods,
CPUTarget: finalCpuPercentTarget, CPUTarget: finalCPUPercentTarget,
reportedLevels: []uint64{ reportedLevels: []uint64{
totalUsedCPUOfAllPods / 10, totalUsedCPUOfAllPods / 10,
totalUsedCPUOfAllPods / 10, totalUsedCPUOfAllPods / 10,
...@@ -1563,7 +1563,7 @@ func TestComputedToleranceAlgImplementation(t *testing.T) { ...@@ -1563,7 +1563,7 @@ func TestComputedToleranceAlgImplementation(t *testing.T) {
resource.MustParse(fmt.Sprint(perPodRequested) + "m"), resource.MustParse(fmt.Sprint(perPodRequested) + "m"),
resource.MustParse(fmt.Sprint(perPodRequested) + "m"), resource.MustParse(fmt.Sprint(perPodRequested) + "m"),
}, },
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
...@@ -1571,8 +1571,8 @@ func TestComputedToleranceAlgImplementation(t *testing.T) { ...@@ -1571,8 +1571,8 @@ func TestComputedToleranceAlgImplementation(t *testing.T) {
// Reuse the data structure above, now testing "unscaling". // Reuse the data structure above, now testing "unscaling".
// Now, we test that no scaling happens if we are in a very close margin to the tolerance // Now, we test that no scaling happens if we are in a very close margin to the tolerance
target = math.Abs(1/(requestedToUsed*(1-tolerance))) + .004 target = math.Abs(1/(requestedToUsed*(1-tolerance))) + .004
finalCpuPercentTarget = int32(target * 100) finalCPUPercentTarget = int32(target * 100)
tc.CPUTarget = finalCpuPercentTarget tc.CPUTarget = finalCPUPercentTarget
tc.initialReplicas = startPods tc.initialReplicas = startPods
tc.desiredReplicas = startPods tc.desiredReplicas = startPods
tc.expectedConditions = statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{ tc.expectedConditions = statusOkWithOverrides(autoscalingv2.HorizontalPodAutoscalerCondition{
...@@ -1593,7 +1593,7 @@ func TestScaleUpRCImmediately(t *testing.T) { ...@@ -1593,7 +1593,7 @@ func TestScaleUpRCImmediately(t *testing.T) {
verifyCPUCurrent: false, verifyCPUCurrent: false,
reportedLevels: []uint64{0, 0, 0, 0}, reportedLevels: []uint64{0, 0, 0, 0},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
lastScaleTime: &time, lastScaleTime: &time,
expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{ expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{
{Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededRescale"}, {Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededRescale"},
...@@ -1612,7 +1612,7 @@ func TestScaleDownRCImmediately(t *testing.T) { ...@@ -1612,7 +1612,7 @@ func TestScaleDownRCImmediately(t *testing.T) {
CPUTarget: 50, CPUTarget: 50,
reportedLevels: []uint64{8000, 9500, 1000}, reportedLevels: []uint64{8000, 9500, 1000},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")},
useMetricsApi: true, useMetricsAPI: true,
lastScaleTime: &time, lastScaleTime: &time,
expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{ expectedConditions: []autoscalingv1.HorizontalPodAutoscalerCondition{
{Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededRescale"}, {Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededRescale"},
...@@ -1633,7 +1633,7 @@ func TestAvoidUncessaryUpdates(t *testing.T) { ...@@ -1633,7 +1633,7 @@ func TestAvoidUncessaryUpdates(t *testing.T) {
reportedLevels: []uint64{400, 500, 700}, reportedLevels: []uint64{400, 500, 700},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
reportedPodReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse}, reportedPodReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse},
useMetricsApi: true, useMetricsAPI: true,
} }
testClient, _, _ := tc.prepareTestClient(t) testClient, _, _ := tc.prepareTestClient(t)
tc.testClient = testClient tc.testClient = testClient
......
...@@ -86,7 +86,7 @@ type legacyTestCase struct { ...@@ -86,7 +86,7 @@ type legacyTestCase struct {
statusUpdated bool statusUpdated bool
eventCreated bool eventCreated bool
verifyEvents bool verifyEvents bool
useMetricsApi bool useMetricsAPI bool
metricsTarget []autoscalingv2.MetricSpec metricsTarget []autoscalingv2.MetricSpec
// Channel with names of HPA objects which we have reconciled. // Channel with names of HPA objects which we have reconciled.
processed chan string processed chan string
...@@ -319,7 +319,7 @@ func (tc *legacyTestCase) prepareTestClient(t *testing.T) *fake.Clientset { ...@@ -319,7 +319,7 @@ func (tc *legacyTestCase) prepareTestClient(t *testing.T) *fake.Clientset {
var heapsterRawMemResponse []byte var heapsterRawMemResponse []byte
if tc.useMetricsApi { if tc.useMetricsAPI {
metrics := metricsapi.PodMetricsList{} metrics := metricsapi.PodMetricsList{}
for i, cpu := range tc.reportedLevels { for i, cpu := range tc.reportedLevels {
podMetric := metricsapi.PodMetrics{ podMetric := metricsapi.PodMetrics{
...@@ -530,7 +530,7 @@ func LegacyTestScaleUp(t *testing.T) { ...@@ -530,7 +530,7 @@ func LegacyTestScaleUp(t *testing.T) {
verifyCPUCurrent: true, verifyCPUCurrent: true,
reportedLevels: []uint64{300, 500, 700}, reportedLevels: []uint64{300, 500, 700},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -547,7 +547,7 @@ func LegacyTestScaleUpUnreadyLessScale(t *testing.T) { ...@@ -547,7 +547,7 @@ func LegacyTestScaleUpUnreadyLessScale(t *testing.T) {
reportedLevels: []uint64{300, 500, 700}, reportedLevels: []uint64{300, 500, 700},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
reportedPodReadiness: []v1.ConditionStatus{v1.ConditionFalse, v1.ConditionTrue, v1.ConditionTrue}, reportedPodReadiness: []v1.ConditionStatus{v1.ConditionFalse, v1.ConditionTrue, v1.ConditionTrue},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -564,7 +564,7 @@ func LegacyTestScaleUpUnreadyNoScale(t *testing.T) { ...@@ -564,7 +564,7 @@ func LegacyTestScaleUpUnreadyNoScale(t *testing.T) {
reportedLevels: []uint64{400, 500, 700}, reportedLevels: []uint64{400, 500, 700},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
reportedPodReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse}, reportedPodReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -579,7 +579,7 @@ func LegacyTestScaleUpDeployment(t *testing.T) { ...@@ -579,7 +579,7 @@ func LegacyTestScaleUpDeployment(t *testing.T) {
verifyCPUCurrent: true, verifyCPUCurrent: true,
reportedLevels: []uint64{300, 500, 700}, reportedLevels: []uint64{300, 500, 700},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
resource: &fakeResource{ resource: &fakeResource{
name: "test-dep", name: "test-dep",
apiVersion: "extensions/v1beta1", apiVersion: "extensions/v1beta1",
...@@ -599,7 +599,7 @@ func LegacyTestScaleUpReplicaSet(t *testing.T) { ...@@ -599,7 +599,7 @@ func LegacyTestScaleUpReplicaSet(t *testing.T) {
verifyCPUCurrent: true, verifyCPUCurrent: true,
reportedLevels: []uint64{300, 500, 700}, reportedLevels: []uint64{300, 500, 700},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
resource: &fakeResource{ resource: &fakeResource{
name: "test-replicaset", name: "test-replicaset",
apiVersion: "extensions/v1beta1", apiVersion: "extensions/v1beta1",
...@@ -687,7 +687,7 @@ func LegacyTestScaleDown(t *testing.T) { ...@@ -687,7 +687,7 @@ func LegacyTestScaleDown(t *testing.T) {
verifyCPUCurrent: true, verifyCPUCurrent: true,
reportedLevels: []uint64{100, 300, 500, 250, 250}, reportedLevels: []uint64{100, 300, 500, 250, 250},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -725,7 +725,7 @@ func LegacyTestScaleDownIgnoresUnreadyPods(t *testing.T) { ...@@ -725,7 +725,7 @@ func LegacyTestScaleDownIgnoresUnreadyPods(t *testing.T) {
verifyCPUCurrent: true, verifyCPUCurrent: true,
reportedLevels: []uint64{100, 300, 500, 250, 250}, reportedLevels: []uint64{100, 300, 500, 250, 250},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
reportedPodReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionTrue, v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse}, reportedPodReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionTrue, v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse},
} }
tc.runTest(t) tc.runTest(t)
...@@ -740,7 +740,7 @@ func LegacyTestTolerance(t *testing.T) { ...@@ -740,7 +740,7 @@ func LegacyTestTolerance(t *testing.T) {
CPUTarget: 100, CPUTarget: 100,
reportedLevels: []uint64{1010, 1030, 1020}, reportedLevels: []uint64{1010, 1030, 1020},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -775,7 +775,7 @@ func LegacyTestMinReplicas(t *testing.T) { ...@@ -775,7 +775,7 @@ func LegacyTestMinReplicas(t *testing.T) {
CPUTarget: 90, CPUTarget: 90,
reportedLevels: []uint64{10, 95, 10}, reportedLevels: []uint64{10, 95, 10},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -789,7 +789,7 @@ func LegacyTestZeroReplicas(t *testing.T) { ...@@ -789,7 +789,7 @@ func LegacyTestZeroReplicas(t *testing.T) {
CPUTarget: 90, CPUTarget: 90,
reportedLevels: []uint64{}, reportedLevels: []uint64{},
reportedCPURequests: []resource.Quantity{}, reportedCPURequests: []resource.Quantity{},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -803,7 +803,7 @@ func LegacyTestTooFewReplicas(t *testing.T) { ...@@ -803,7 +803,7 @@ func LegacyTestTooFewReplicas(t *testing.T) {
CPUTarget: 90, CPUTarget: 90,
reportedLevels: []uint64{}, reportedLevels: []uint64{},
reportedCPURequests: []resource.Quantity{}, reportedCPURequests: []resource.Quantity{},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -817,7 +817,7 @@ func LegacyTestTooManyReplicas(t *testing.T) { ...@@ -817,7 +817,7 @@ func LegacyTestTooManyReplicas(t *testing.T) {
CPUTarget: 90, CPUTarget: 90,
reportedLevels: []uint64{}, reportedLevels: []uint64{},
reportedCPURequests: []resource.Quantity{}, reportedCPURequests: []resource.Quantity{},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -831,7 +831,7 @@ func LegacyTestMaxReplicas(t *testing.T) { ...@@ -831,7 +831,7 @@ func LegacyTestMaxReplicas(t *testing.T) {
CPUTarget: 90, CPUTarget: 90,
reportedLevels: []uint64{8000, 9500, 1000}, reportedLevels: []uint64{8000, 9500, 1000},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -845,7 +845,7 @@ func LegacyTestSuperfluousMetrics(t *testing.T) { ...@@ -845,7 +845,7 @@ func LegacyTestSuperfluousMetrics(t *testing.T) {
CPUTarget: 100, CPUTarget: 100,
reportedLevels: []uint64{4000, 9500, 3000, 7000, 3200, 2000}, reportedLevels: []uint64{4000, 9500, 3000, 7000, 3200, 2000},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -859,7 +859,7 @@ func LegacyTestMissingMetrics(t *testing.T) { ...@@ -859,7 +859,7 @@ func LegacyTestMissingMetrics(t *testing.T) {
CPUTarget: 100, CPUTarget: 100,
reportedLevels: []uint64{400, 95}, reportedLevels: []uint64{400, 95},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -873,7 +873,7 @@ func LegacyTestEmptyMetrics(t *testing.T) { ...@@ -873,7 +873,7 @@ func LegacyTestEmptyMetrics(t *testing.T) {
CPUTarget: 100, CPUTarget: 100,
reportedLevels: []uint64{}, reportedLevels: []uint64{},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -886,7 +886,7 @@ func LegacyTestEmptyCPURequest(t *testing.T) { ...@@ -886,7 +886,7 @@ func LegacyTestEmptyCPURequest(t *testing.T) {
desiredReplicas: 1, desiredReplicas: 1,
CPUTarget: 100, CPUTarget: 100,
reportedLevels: []uint64{200}, reportedLevels: []uint64{200},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -901,7 +901,7 @@ func LegacyTestEventCreated(t *testing.T) { ...@@ -901,7 +901,7 @@ func LegacyTestEventCreated(t *testing.T) {
reportedLevels: []uint64{200}, reportedLevels: []uint64{200},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.2")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.2")},
verifyEvents: true, verifyEvents: true,
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -916,7 +916,7 @@ func LegacyTestEventNotCreated(t *testing.T) { ...@@ -916,7 +916,7 @@ func LegacyTestEventNotCreated(t *testing.T) {
reportedLevels: []uint64{200, 200}, reportedLevels: []uint64{200, 200},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.4"), resource.MustParse("0.4")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.4"), resource.MustParse("0.4")},
verifyEvents: true, verifyEvents: true,
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -930,7 +930,7 @@ func LegacyTestMissingReports(t *testing.T) { ...@@ -930,7 +930,7 @@ func LegacyTestMissingReports(t *testing.T) {
CPUTarget: 50, CPUTarget: 50,
reportedLevels: []uint64{200}, reportedLevels: []uint64{200},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.2")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.2")},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -944,7 +944,7 @@ func LegacyTestUpscaleCap(t *testing.T) { ...@@ -944,7 +944,7 @@ func LegacyTestUpscaleCap(t *testing.T) {
CPUTarget: 10, CPUTarget: 10,
reportedLevels: []uint64{100, 200, 300}, reportedLevels: []uint64{100, 200, 300},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")},
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
} }
...@@ -966,7 +966,7 @@ func LegacyTestComputedToleranceAlgImplementation(t *testing.T) { ...@@ -966,7 +966,7 @@ func LegacyTestComputedToleranceAlgImplementation(t *testing.T) {
// Force a minimal scaling event by satisfying (tolerance < 1 - resourcesUsedRatio). // Force a minimal scaling event by satisfying (tolerance < 1 - resourcesUsedRatio).
target := math.Abs(1/(requestedToUsed*(1-tolerance))) + .01 target := math.Abs(1/(requestedToUsed*(1-tolerance))) + .01
finalCpuPercentTarget := int32(target * 100) finalCPUPercentTarget := int32(target * 100)
resourcesUsedRatio := float64(totalUsedCPUOfAllPods) / float64(float64(totalRequestedCPUOfAllPods)*target) resourcesUsedRatio := float64(totalUsedCPUOfAllPods) / float64(float64(totalRequestedCPUOfAllPods)*target)
// i.e. .60 * 20 -> scaled down expectation. // i.e. .60 * 20 -> scaled down expectation.
...@@ -978,7 +978,7 @@ func LegacyTestComputedToleranceAlgImplementation(t *testing.T) { ...@@ -978,7 +978,7 @@ func LegacyTestComputedToleranceAlgImplementation(t *testing.T) {
maxReplicas: 1000, maxReplicas: 1000,
initialReplicas: startPods, initialReplicas: startPods,
desiredReplicas: finalPods, desiredReplicas: finalPods,
CPUTarget: finalCpuPercentTarget, CPUTarget: finalCPUPercentTarget,
reportedLevels: []uint64{ reportedLevels: []uint64{
totalUsedCPUOfAllPods / 10, totalUsedCPUOfAllPods / 10,
totalUsedCPUOfAllPods / 10, totalUsedCPUOfAllPods / 10,
...@@ -1003,7 +1003,7 @@ func LegacyTestComputedToleranceAlgImplementation(t *testing.T) { ...@@ -1003,7 +1003,7 @@ func LegacyTestComputedToleranceAlgImplementation(t *testing.T) {
resource.MustParse(fmt.Sprint(perPodRequested) + "m"), resource.MustParse(fmt.Sprint(perPodRequested) + "m"),
resource.MustParse(fmt.Sprint(perPodRequested) + "m"), resource.MustParse(fmt.Sprint(perPodRequested) + "m"),
}, },
useMetricsApi: true, useMetricsAPI: true,
} }
tc.runTest(t) tc.runTest(t)
...@@ -1011,8 +1011,8 @@ func LegacyTestComputedToleranceAlgImplementation(t *testing.T) { ...@@ -1011,8 +1011,8 @@ func LegacyTestComputedToleranceAlgImplementation(t *testing.T) {
// Reuse the data structure above, now testing "unscaling". // Reuse the data structure above, now testing "unscaling".
// Now, we test that no scaling happens if we are in a very close margin to the tolerance // Now, we test that no scaling happens if we are in a very close margin to the tolerance
target = math.Abs(1/(requestedToUsed*(1-tolerance))) + .004 target = math.Abs(1/(requestedToUsed*(1-tolerance))) + .004
finalCpuPercentTarget = int32(target * 100) finalCPUPercentTarget = int32(target * 100)
tc.CPUTarget = finalCpuPercentTarget tc.CPUTarget = finalCPUPercentTarget
tc.initialReplicas = startPods tc.initialReplicas = startPods
tc.desiredReplicas = startPods tc.desiredReplicas = startPods
tc.runTest(t) tc.runTest(t)
...@@ -1028,7 +1028,7 @@ func LegacyTestScaleUpRCImmediately(t *testing.T) { ...@@ -1028,7 +1028,7 @@ func LegacyTestScaleUpRCImmediately(t *testing.T) {
verifyCPUCurrent: false, verifyCPUCurrent: false,
reportedLevels: []uint64{0, 0, 0, 0}, reportedLevels: []uint64{0, 0, 0, 0},
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")}, reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
useMetricsApi: true, useMetricsAPI: true,
lastScaleTime: &time, lastScaleTime: &time,
} }
tc.runTest(t) tc.runTest(t)
...@@ -1044,7 +1044,7 @@ func LegacyTestScaleDownRCImmediately(t *testing.T) { ...@@ -1044,7 +1044,7 @@ func LegacyTestScaleDownRCImmediately(t *testing.T) {
CPUTarget: 50, CPUTarget: 50,
reportedLevels: []uint64{8000, 9500, 1000}, reportedLevels: []uint64{8000, 9500, 1000},
reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")}, reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")},
useMetricsApi: true, useMetricsAPI: true,
lastScaleTime: &time, lastScaleTime: &time,
} }
tc.runTest(t) tc.runTest(t)
......
...@@ -604,7 +604,7 @@ func LegacyTestReplicaCalcComputedToleranceAlgImplementation(t *testing.T) { ...@@ -604,7 +604,7 @@ func LegacyTestReplicaCalcComputedToleranceAlgImplementation(t *testing.T) {
// Force a minimal scaling event by satisfying (tolerance < 1 - resourcesUsedRatio). // Force a minimal scaling event by satisfying (tolerance < 1 - resourcesUsedRatio).
target := math.Abs(1/(requestedToUsed*(1-tolerance))) + .01 target := math.Abs(1/(requestedToUsed*(1-tolerance))) + .01
finalCpuPercentTarget := int32(target * 100) finalCPUPercentTarget := int32(target * 100)
resourcesUsedRatio := float64(totalUsedCPUOfAllPods) / float64(float64(totalRequestedCPUOfAllPods)*target) resourcesUsedRatio := float64(totalUsedCPUOfAllPods) / float64(float64(totalRequestedCPUOfAllPods)*target)
// i.e. .60 * 20 -> scaled down expectation. // i.e. .60 * 20 -> scaled down expectation.
...@@ -641,7 +641,7 @@ func LegacyTestReplicaCalcComputedToleranceAlgImplementation(t *testing.T) { ...@@ -641,7 +641,7 @@ func LegacyTestReplicaCalcComputedToleranceAlgImplementation(t *testing.T) {
resource.MustParse(fmt.Sprint(perPodRequested) + "m"), resource.MustParse(fmt.Sprint(perPodRequested) + "m"),
}, },
targetUtilization: finalCpuPercentTarget, targetUtilization: finalCPUPercentTarget,
expectedUtilization: int32(totalUsedCPUOfAllPods*100) / totalRequestedCPUOfAllPods, expectedUtilization: int32(totalUsedCPUOfAllPods*100) / totalRequestedCPUOfAllPods,
expectedValue: numContainersPerPod * totalUsedCPUOfAllPods / 10, expectedValue: numContainersPerPod * totalUsedCPUOfAllPods / 10,
}, },
...@@ -652,8 +652,8 @@ func LegacyTestReplicaCalcComputedToleranceAlgImplementation(t *testing.T) { ...@@ -652,8 +652,8 @@ func LegacyTestReplicaCalcComputedToleranceAlgImplementation(t *testing.T) {
// Reuse the data structure above, now testing "unscaling". // Reuse the data structure above, now testing "unscaling".
// Now, we test that no scaling happens if we are in a very close margin to the tolerance // Now, we test that no scaling happens if we are in a very close margin to the tolerance
target = math.Abs(1/(requestedToUsed*(1-tolerance))) + .004 target = math.Abs(1/(requestedToUsed*(1-tolerance))) + .004
finalCpuPercentTarget = int32(target * 100) finalCPUPercentTarget = int32(target * 100)
tc.resource.targetUtilization = finalCpuPercentTarget tc.resource.targetUtilization = finalCPUPercentTarget
tc.currentReplicas = startPods tc.currentReplicas = startPods
tc.expectedReplicas = startPods tc.expectedReplicas = startPods
tc.runTest(t) tc.runTest(t)
......
...@@ -46,7 +46,7 @@ func (r *FixedItemIntervalRateLimiter) NumRequeues(item interface{}) int { ...@@ -46,7 +46,7 @@ func (r *FixedItemIntervalRateLimiter) NumRequeues(item interface{}) int {
func (r *FixedItemIntervalRateLimiter) Forget(item interface{}) { func (r *FixedItemIntervalRateLimiter) Forget(item interface{}) {
} }
// NewDefaultHPARateLimitter creates a rate limitter which limits overall (as per the // NewDefaultHPARateLimiter creates a rate limitter which limits overall (as per the
// default controller rate limiter), as well as per the resync interval // default controller rate limiter), as well as per the resync interval
func NewDefaultHPARateLimiter(interval time.Duration) workqueue.RateLimiter { func NewDefaultHPARateLimiter(interval time.Duration) workqueue.RateLimiter {
return NewFixedItemIntervalRateLimiter(interval) return NewFixedItemIntervalRateLimiter(interval)
......
...@@ -206,36 +206,35 @@ func (tc *replicaCalcTestCase) prepareTestClient(t *testing.T) (*fake.Clientset, ...@@ -206,36 +206,35 @@ func (tc *replicaCalcTestCase) prepareTestClient(t *testing.T) (*fake.Clientset,
} }
return true, &metrics, nil return true, &metrics, nil
} else { }
name := getForAction.GetName() name := getForAction.GetName()
mapper := api.Registry.RESTMapper() mapper := api.Registry.RESTMapper()
metrics := &cmapi.MetricValueList{} metrics := &cmapi.MetricValueList{}
assert.NotNil(t, tc.metric.singleObject, "should have only requested a single-object metric when calling GetObjectMetricReplicas") assert.NotNil(t, tc.metric.singleObject, "should have only requested a single-object metric when calling GetObjectMetricReplicas")
gk := schema.FromAPIVersionAndKind(tc.metric.singleObject.APIVersion, tc.metric.singleObject.Kind).GroupKind() gk := schema.FromAPIVersionAndKind(tc.metric.singleObject.APIVersion, tc.metric.singleObject.Kind).GroupKind()
mapping, err := mapper.RESTMapping(gk) mapping, err := mapper.RESTMapping(gk)
if err != nil { if err != nil {
return true, nil, fmt.Errorf("unable to get mapping for %s: %v", gk.String(), err) return true, nil, fmt.Errorf("unable to get mapping for %s: %v", gk.String(), err)
} }
groupResource := schema.GroupResource{Group: mapping.GroupVersionKind.Group, Resource: mapping.Resource} groupResource := schema.GroupResource{Group: mapping.GroupVersionKind.Group, Resource: mapping.Resource}
assert.Equal(t, groupResource.String(), getForAction.GetResource().Resource, "should have requested metrics for the resource matching the GroupKind passed in") assert.Equal(t, groupResource.String(), getForAction.GetResource().Resource, "should have requested metrics for the resource matching the GroupKind passed in")
assert.Equal(t, tc.metric.singleObject.Name, name, "should have requested metrics for the object matching the name passed in") assert.Equal(t, tc.metric.singleObject.Name, name, "should have requested metrics for the object matching the name passed in")
metrics.Items = []cmapi.MetricValue{ metrics.Items = []cmapi.MetricValue{
{ {
DescribedObject: v1.ObjectReference{ DescribedObject: v1.ObjectReference{
Kind: tc.metric.singleObject.Kind, Kind: tc.metric.singleObject.Kind,
APIVersion: tc.metric.singleObject.APIVersion, APIVersion: tc.metric.singleObject.APIVersion,
Name: name, Name: name,
},
Timestamp: metav1.Time{Time: tc.timestamp},
MetricName: tc.metric.name,
Value: *resource.NewMilliQuantity(int64(tc.metric.levels[0]), resource.DecimalSI),
}, },
} Timestamp: metav1.Time{Time: tc.timestamp},
MetricName: tc.metric.name,
return true, metrics, nil Value: *resource.NewMilliQuantity(int64(tc.metric.levels[0]), resource.DecimalSI),
},
} }
return true, metrics, nil
}) })
return fakeClient, fakeMetricsClient, fakeCMClient return fakeClient, fakeMetricsClient, fakeCMClient
...@@ -729,7 +728,7 @@ func TestReplicaCalcComputedToleranceAlgImplementation(t *testing.T) { ...@@ -729,7 +728,7 @@ func TestReplicaCalcComputedToleranceAlgImplementation(t *testing.T) {
// Force a minimal scaling event by satisfying (tolerance < 1 - resourcesUsedRatio). // Force a minimal scaling event by satisfying (tolerance < 1 - resourcesUsedRatio).
target := math.Abs(1/(requestedToUsed*(1-tolerance))) + .01 target := math.Abs(1/(requestedToUsed*(1-tolerance))) + .01
finalCpuPercentTarget := int32(target * 100) finalCPUPercentTarget := int32(target * 100)
resourcesUsedRatio := float64(totalUsedCPUOfAllPods) / float64(float64(totalRequestedCPUOfAllPods)*target) resourcesUsedRatio := float64(totalUsedCPUOfAllPods) / float64(float64(totalRequestedCPUOfAllPods)*target)
// i.e. .60 * 20 -> scaled down expectation. // i.e. .60 * 20 -> scaled down expectation.
...@@ -766,7 +765,7 @@ func TestReplicaCalcComputedToleranceAlgImplementation(t *testing.T) { ...@@ -766,7 +765,7 @@ func TestReplicaCalcComputedToleranceAlgImplementation(t *testing.T) {
resource.MustParse(fmt.Sprint(perPodRequested) + "m"), resource.MustParse(fmt.Sprint(perPodRequested) + "m"),
}, },
targetUtilization: finalCpuPercentTarget, targetUtilization: finalCPUPercentTarget,
expectedUtilization: int32(totalUsedCPUOfAllPods*100) / totalRequestedCPUOfAllPods, expectedUtilization: int32(totalUsedCPUOfAllPods*100) / totalRequestedCPUOfAllPods,
expectedValue: numContainersPerPod * totalUsedCPUOfAllPods / 10, expectedValue: numContainersPerPod * totalUsedCPUOfAllPods / 10,
}, },
...@@ -777,8 +776,8 @@ func TestReplicaCalcComputedToleranceAlgImplementation(t *testing.T) { ...@@ -777,8 +776,8 @@ func TestReplicaCalcComputedToleranceAlgImplementation(t *testing.T) {
// Reuse the data structure above, now testing "unscaling". // Reuse the data structure above, now testing "unscaling".
// Now, we test that no scaling happens if we are in a very close margin to the tolerance // Now, we test that no scaling happens if we are in a very close margin to the tolerance
target = math.Abs(1/(requestedToUsed*(1-tolerance))) + .004 target = math.Abs(1/(requestedToUsed*(1-tolerance))) + .004
finalCpuPercentTarget = int32(target * 100) finalCPUPercentTarget = int32(target * 100)
tc.resource.targetUtilization = finalCpuPercentTarget tc.resource.targetUtilization = finalCPUPercentTarget
tc.currentReplicas = startPods tc.currentReplicas = startPods
tc.expectedReplicas = startPods tc.expectedReplicas = startPods
tc.runTest(t) tc.runTest(t)
......
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