From b895a74a2ef14ab890a8f3be407395bc8b9c2db9 Mon Sep 17 00:00:00 2001 From: bruceauyeung Date: Thu, 22 Dec 2016 16:14:48 +0800 Subject: [PATCH] small code improvements and fix some typos Signed-off-by: bruceauyeung --- pkg/controller/podautoscaler/horizontal.go | 6 +++--- pkg/controller/podautoscaler/replica_calculator.go | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/controller/podautoscaler/horizontal.go b/pkg/controller/podautoscaler/horizontal.go index 6436f05285..d39f6953a0 100644 --- a/pkg/controller/podautoscaler/horizontal.go +++ b/pkg/controller/podautoscaler/horizontal.go @@ -355,8 +355,8 @@ func (a *HorizontalController) reconcileAutoscaler(hpav1 *autoscalingv1.Horizont // Do not upscale too much to prevent incorrect rapid increase of the number of master replicas caused by // bogus CPU usage report from heapster/kubelet (like in issue #32304). - if desiredReplicas > calculateScaleUpLimit(currentReplicas) { - desiredReplicas = calculateScaleUpLimit(currentReplicas) + if scaleUpLimit := calculateScaleUpLimit(currentReplicas); desiredReplicas > scaleUpLimit { + desiredReplicas = scaleUpLimit } rescale = shouldScale(hpa, currentReplicas, desiredReplicas, timestamp) @@ -370,7 +370,7 @@ func (a *HorizontalController) reconcileAutoscaler(hpav1 *autoscalingv1.Horizont return fmt.Errorf("failed to rescale %s: %v", reference, err) } a.eventRecorder.Eventf(hpa, v1.EventTypeNormal, "SuccessfulRescale", "New size: %d; reason: %s", desiredReplicas, rescaleReason) - glog.Infof("Successfull rescale of %s, old size: %d, new size: %d, reason: %s", + glog.Infof("Successful rescale of %s, old size: %d, new size: %d, reason: %s", hpa.Name, currentReplicas, desiredReplicas, rescaleReason) } else { glog.V(4).Infof("decided not to scale %s to %v (last scale time was %s)", reference, desiredReplicas, hpa.Status.LastScaleTime) diff --git a/pkg/controller/podautoscaler/replica_calculator.go b/pkg/controller/podautoscaler/replica_calculator.go index a359a8ef74..6e2ad0ad61 100644 --- a/pkg/controller/podautoscaler/replica_calculator.go +++ b/pkg/controller/podautoscaler/replica_calculator.go @@ -55,11 +55,12 @@ func (c *ReplicaCalculator) GetResourceReplicas(currentReplicas int32, targetUti return 0, 0, 0, time.Time{}, fmt.Errorf("unable to get pods while calculating replica count: %v", err) } - if len(podList.Items) == 0 { + itemsLen := len(podList.Items) + if itemsLen == 0 { return 0, 0, 0, time.Time{}, fmt.Errorf("no pods returned by selector while calculating replica count") } - requests := make(map[string]int64, len(podList.Items)) + requests := make(map[string]int64, itemsLen) readyPodCount := 0 unreadyPods := sets.NewString() missingPods := sets.NewString()