Skip to content

Commit

Permalink
chore: fallback - patch ScaledObject.Status only when there is a diff…
Browse files Browse the repository at this point in the history
…erence (#5871)

Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>
  • Loading branch information
zroubalik committed Jun 24, 2024
1 parent 8927121 commit b2746a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ New deprecation(s):

### Other

- TODO ([#XXX](https://github.com/kedacore/keda/issues/XXX))
- **General**: Added Pre Regex check before building image in e2e test ([#5783](https://github.com/kedacore/keda/issues/5783))
- **General**: Reduce the number of ScaledObject.Status updates in the fallback ([#5624](https://github.com/kedacore/keda/issues/5624))

## v2.14.0

Expand Down
12 changes: 8 additions & 4 deletions pkg/fallback/fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package fallback

import (
"context"
"reflect"
"strconv"

v2 "k8s.io/api/autoscaling/v2"
Expand Down Expand Up @@ -137,10 +138,13 @@ func updateStatus(ctx context.Context, client runtimeclient.Client, scaledObject
status.Conditions.SetFallbackCondition(metav1.ConditionFalse, "NoFallbackFound", "No fallbacks are active on this scaled object")
}

scaledObject.Status = *status
err := client.Status().Patch(ctx, scaledObject, patch)
if err != nil {
log.Error(err, "failed to patch ScaledObjects Status", "scaledObject.Namespace", scaledObject.Namespace, "scaledObject.Name", scaledObject.Name)
// Update status only if it has changed
if !reflect.DeepEqual(scaledObject.Status, *status) {
scaledObject.Status = *status
err := client.Status().Patch(ctx, scaledObject, patch)
if err != nil {
log.Error(err, "failed to patch ScaledObjects Status", "scaledObject.Namespace", scaledObject.Namespace, "scaledObject.Name", scaledObject.Name)
}
}
}

Expand Down

0 comments on commit b2746a8

Please sign in to comment.