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
...@@ -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