readyPodCount, unreadyPods, missingPods, ignoredPods := groupPods(podList, metrics, resource, c.cpuInitializationPeriod, c.delayOfInitialReadinessStatus"> readyPodCount, unreadyPods, missingPods, ignoredPods := groupPods(podList, metrics, resource, c.cpuInitializationPeriod, c.delayOfInitialReadinessStatus"> readyPodCount, unreadyPods, missingPods, ignoredPods := groupPods(podList, metrics, resource, c.cpuInitializationPeriod, c.delayOfInitialReadinessStatus">
reconcileAutoscaler(hpav1Shared *autoscalingv1.HorizontalPodAutoscaler, key string)-->
computeReplicasForMetrics()-->
a.computeReplicasForMetric(hpa, metricSpec, specReplicas, statusReplicas, selector, &statuses[i])-->
switch spec.Type {
case autoscalingv2.ObjectMetricSourceType:
case autoscalingv2.PodsMetricSourceType:
a.computeStatusForPodsMetric(specReplicas, spec, hpa, selector, status, metricSelector)-->
a.replicaCalc.GetMetricReplicas(currentReplicas, metricSpec.Pods.Target.AverageValue.MilliValue(), metricSpec.Pods.Metric.Name, hpa.Namespace, selector, metricSelector)-->
c.metricsClient.GetRawMetric(metricName, namespace, selector, metricSelector) // get data from metrics server
c.calcPlainMetricReplicas(metrics, currentReplicas, targetUtilization, namespace, selector, v1.ResourceName(""))-->
readyPodCount, unreadyPods, missingPods, ignoredPods := groupPods(podList, metrics, resource, c.cpuInitializationPeriod, c.delayOfInitialReadinessStatus)
removeMetricsForPods(metrics, ignoredPods)
removeMetricsForPods(metrics, unreadyPods)
usageRatio, utilization := metricsclient.GetMetricUtilizationRatio(metrics, targetUtilization) // 计算目标utilization与当前utilization的比值
newReplicas := int32(math.Ceil(newUsageRatio * float64(len(metrics)))) // len(metrics)=有效pod数量
case autoscalingv2.ResourceMetricSourceType:
case autoscalingv2.ContainerResourceMetricSourceType:
case autoscalingv2.ExternalMetricSourceType:
a.computeStatusForExternalMetric(specReplicas, statusReplicas, spec, hpa, selector, status)-->
a.replicaCalc.GetExternalPerPodMetricReplicas(statusReplicas, metricSpec.External.Target.AverageValue.MilliValue(), metricSpec.External.Metric.Name, hpa.Namespace, metricSpec.External.Metric.Selector)
metrics, timestamp, err := c.metricsClient.GetExternalMetric(metricName, namespace, metricLabelSelector)
}
desiredReplicas = a.normalizeDesiredReplicasWithBehaviors(hpa, key, currentReplicas, desiredReplicas, minReplicas)
a.updateStatusIfNeeded(hpaStatusOriginal, hpa)