From b2746a81dbb0ef978aa287bfe8b1671e38471a7a Mon Sep 17 00:00:00 2001 From: Zbynek Roubalik Date: Mon, 24 Jun 2024 14:39:34 +0200 Subject: [PATCH] chore: fallback - patch ScaledObject.Status only when there is a difference (#5871) Signed-off-by: Zbynek Roubalik --- CHANGELOG.md | 2 +- pkg/fallback/fallback.go | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1498ccf48f..1482554cf2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pkg/fallback/fallback.go b/pkg/fallback/fallback.go index 59dac517519..967453cf4d5 100644 --- a/pkg/fallback/fallback.go +++ b/pkg/fallback/fallback.go @@ -18,6 +18,7 @@ package fallback import ( "context" + "reflect" "strconv" v2 "k8s.io/api/autoscaling/v2" @@ -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) + } } }