diff --git a/pkg/controller/ehpa/hpa.go b/pkg/controller/ehpa/hpa.go index 645606e47..ec9cda8ae 100644 --- a/pkg/controller/ehpa/hpa.go +++ b/pkg/controller/ehpa/hpa.go @@ -247,7 +247,7 @@ func (c *EffectiveHPAController) GetHPAMetrics(ctx context.Context, ehpa *autosc continue } - name := utils.GetPredictionMetricName(metric.Type, false) + name := utils.GetPredictionMetricName(metric.Type) if len(name) == 0 { continue } @@ -299,7 +299,7 @@ func GetCronMetricSpecsForHPA(ehpa *autoscalingapi.EffectiveHorizontalPodAutosca Type: autoscalingv2.ExternalMetricSourceType, External: &autoscalingv2.ExternalMetricSource{ Metric: autoscalingv2.MetricIdentifier{ - Name: utils.GetPredictionMetricName(autoscalingv2.PodsMetricSourceType, true), + Name: utils.GetCronMetricName(), Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ "targetKind": ehpa.Spec.ScaleTargetRef.Kind, diff --git a/pkg/utils/ehpa.go b/pkg/utils/ehpa.go index 19427a88d..7640c4cb7 100644 --- a/pkg/utils/ehpa.go +++ b/pkg/utils/ehpa.go @@ -17,13 +17,11 @@ func IsEHPAPredictionEnabled(ehpa *autoscalingapi.EffectiveHorizontalPodAutoscal func IsEHPAHasPredictionMetric(ehpa *autoscalingapi.EffectiveHorizontalPodAutoscaler) bool { for _, metric := range ehpa.Spec.Metrics { - if metric.Type == autoscalingv2.ResourceMetricSourceType { - metricName := GetPredictionMetricName(metric.Type, false) - if len(metricName) == 0 { - continue - } - return true + metricName := GetPredictionMetricName(metric.Type) + if len(metricName) == 0 { + continue } + return true } for key := range ehpa.Annotations { @@ -39,19 +37,20 @@ func IsEHPACronEnabled(ehpa *autoscalingapi.EffectiveHorizontalPodAutoscaler) bo } // GetPredictionMetricName return metric name used by prediction -func GetPredictionMetricName(sourceType autoscalingv2.MetricSourceType, isCron bool) (metricName string) { - if isCron { - metricName = known.MetricNameCron - } else { - switch sourceType { - case autoscalingv2.ResourceMetricSourceType, autoscalingv2.PodsMetricSourceType, autoscalingv2.ExternalMetricSourceType: - metricName = known.MetricNamePrediction - } +func GetPredictionMetricName(sourceType autoscalingv2.MetricSourceType) (metricName string) { + switch sourceType { + case autoscalingv2.ResourceMetricSourceType, autoscalingv2.PodsMetricSourceType, autoscalingv2.ExternalMetricSourceType: + metricName = known.MetricNamePrediction } return metricName } +// GetCronMetricName return metric name used by cron +func GetCronMetricName() string { + return known.MetricNameCron +} + // GetGeneralPredictionMetricName return metric name used by prediction func GetMetricIdentifier(metric autoscalingv2.MetricSpec, name string) string { var prefix string