Skip to content

Commit

Permalink
fix: unnecessary HPA updates when cpu utilization trigger is used
Browse files Browse the repository at this point in the history
Signed-off-by: uucloud <uucloud@qq.com>
  • Loading branch information
uucloud committed Jul 11, 2024
1 parent 3f75aad commit 2094d4e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions controllers/keda/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (r *ScaledObjectReconciler) getScaledObjectMetricSpecs(ctx context.Context,

metricSpecs := cache.GetMetricSpecForScaling(ctx)
var mSpecs []autoscalingv2.MetricSpec
var hasCpuUtilization bool
var hasCPUUtilization bool
var cpuUtilization autoscalingv2.MetricSpec

for _, metricSpec := range metricSpecs {
Expand All @@ -232,10 +232,10 @@ func (r *ScaledObjectReconciler) getScaledObjectMetricSpecs(ctx context.Context,
// and only one is retained. This prevents the KEDA controller from continuously updating.
// see https://github.com/kedacore/keda/issues/5821 for details
if target.Type == autoscalingv2.UtilizationMetricType && string(metricSpec.Resource.Name) == "cpu" {
if hasCpuUtilization {
if hasCPUUtilization {
continue
}
hasCpuUtilization = true
hasCPUUtilization = true
cpuUtilization = metricSpec
continue
}
Expand All @@ -258,7 +258,7 @@ func (r *ScaledObjectReconciler) getScaledObjectMetricSpecs(ctx context.Context,
}
scaledObjectMetricSpecs = append(scaledObjectMetricSpecs, mSpecs...)

if hasCpuUtilization {
if hasCPUUtilization {
resourceMetricNames = append(resourceMetricNames, "cpu")
scaledObjectMetricSpecs = append(scaledObjectMetricSpecs, cpuUtilization)
}
Expand Down

0 comments on commit 2094d4e

Please sign in to comment.