Skip to content

Commit

Permalink
Fix unnecessary HPA updates when Resource based Trigger is used (keda…
Browse files Browse the repository at this point in the history
…core#1541)

Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
  • Loading branch information
zroubalik authored and ycabrer committed Mar 1, 2021
1 parent d124d41 commit 121e462
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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 121e462

Please sign in to comment.