diff --git a/CHANGELOG.md b/CHANGELOG.md index 92b8bc4637f..8c28c7bbeae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,7 @@ - Serve OpenAPI spec from KEDA Metrics Apiserver ([#1512](https://github.com/kedacore/keda/pull/1512)) - Support metrics with multiple dimensions and configurable metricValues on AWS Cloudwatch Scaler ([#1230](https://github.com/kedacore/keda/issues/1230)) - Show `MIN/MAX` replica counts when using `kubectl get scaledobject/scaledjob` ([#1534](https://github.com/kedacore/keda/pull/1534)) +- Fix unnecessary HPA updates when Resource based Trigger is used ([#1541](https://github.com/kedacore/keda/pull/1541)) ### Breaking Changes diff --git a/controllers/hpa.go b/controllers/hpa.go index 33548899fed..1fd645f9324 100644 --- a/controllers/hpa.go +++ b/controllers/hpa.go @@ -3,6 +3,7 @@ package controllers import ( "context" "fmt" + "sort" "github.com/go-logr/logr" version "github.com/kedacore/keda/v2/version" @@ -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