Skip to content

Commit

Permalink
Fix unnecessary HPA updates
Browse files Browse the repository at this point in the history
Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
  • Loading branch information
Zbynek Roubalik committed Jan 27, 2021
1 parent 51d16da commit d399288
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions controllers/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"context"
"fmt"
"sort"

"github.com/go-logr/logr"
version "github.com/kedacore/keda/v2/version"
Expand Down Expand Up @@ -161,6 +162,12 @@ func (r *ScaledObjectReconciler) getScaledObjectMetricSpecs(logger logr.Logger,
scaler.Close()
}

// sort metrics in ScaledObject, this way we always check the same resource in Reconcile loop and we can prevent unnecessary HPA updates,
// see https://github.com/kedacore/keda/issues/1531 for details
sort.Slice(scaledObjectMetricSpecs, func(i, j int) bool {
return scaledObjectMetricSpecs[i].Type < scaledObjectMetricSpecs[j].Type
})

// store External.MetricNames,Resource.MetricsNames used by scalers defined in the ScaledObject
status := scaledObject.Status.DeepCopy()
status.ExternalMetricNames = externalMetricNames
Expand Down

0 comments on commit d399288

Please sign in to comment.