From d4851d0837ed9078def30a963a482b872d79da60 Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Thu, 7 Nov 2024 21:57:21 +0100 Subject: [PATCH 1/2] fix: Paused ScaledObject count is reported correctly after operator restart Signed-off-by: Jorge Turrado --- CHANGELOG.md | 2 +- controllers/keda/scaledobject_controller.go | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9944e57388a..b39a66a2cc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,7 +72,7 @@ Here is an overview of all new **experimental** features: ### Fixes -- TODO ([#XXX](https://github.com/kedacore/keda/issues/XXX)) +- **General**: Paused ScaledObject count is reported correctly after operator restart ([#6321](https://github.com/kedacore/keda/issues/6321)) ### Deprecations diff --git a/controllers/keda/scaledobject_controller.go b/controllers/keda/scaledobject_controller.go index ff6194c4ea7..92c898e2f20 100755 --- a/controllers/keda/scaledobject_controller.go +++ b/controllers/keda/scaledobject_controller.go @@ -209,6 +209,8 @@ func (r *ScaledObjectReconciler) Reconcile(ctx context.Context, req ctrl.Request conditions.SetFallbackCondition(metav1.ConditionFalse, "NoFallbackFound", "No fallbacks are active on this scaled object") } + metricscollector.RecordScaledObjectPaused(scaledObject.Namespace, scaledObject.Name, conditions.GetPausedCondition().Status == metav1.ConditionTrue) + if err := kedastatus.SetStatusConditions(ctx, r.Client, reqLogger, scaledObject, &conditions); err != nil { r.EventEmitter.Emit(scaledObject, req.NamespacedName.Namespace, corev1.EventTypeWarning, eventingv1alpha1.ScaledObjectFailedType, eventreason.ScaledObjectUpdateFailed, err.Error()) return ctrl.Result{}, err @@ -246,12 +248,10 @@ func (r *ScaledObjectReconciler) reconcileScaledObject(ctx context.Context, logg return msg, err } conditions.SetPausedCondition(metav1.ConditionTrue, kedav1alpha1.ScaledObjectConditionPausedReason, msg) - metricscollector.RecordScaledObjectPaused(scaledObject.Namespace, scaledObject.Name, true) return msg, nil } } else if conditions.GetPausedCondition().Status == metav1.ConditionTrue { conditions.SetPausedCondition(metav1.ConditionFalse, "ScaledObjectUnpaused", "pause annotation removed for ScaledObject") - metricscollector.RecordScaledObjectPaused(scaledObject.Namespace, scaledObject.Name, false) } // Check scale target Name is specified @@ -282,11 +282,6 @@ func (r *ScaledObjectReconciler) reconcileScaledObject(ctx context.Context, logg return "ScaledObject doesn't have correct triggers specification", err } - err = r.updateStatusWithTriggersAndAuthsTypes(ctx, logger, scaledObject) - if err != nil { - return "Cannot update ScaledObject status with triggers'types and authentications'types", err - } - // Create a new HPA or update existing one according to ScaledObject newHPACreated, err := r.ensureHPAForScaledObjectExists(ctx, logger, scaledObject, &gvkr) if err != nil { From 2b9bfbf56229fc693ea11047fc1652eaebfec788 Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Thu, 7 Nov 2024 22:06:54 +0100 Subject: [PATCH 2/2] add wrong removed code Signed-off-by: Jorge Turrado --- controllers/keda/scaledobject_controller.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/controllers/keda/scaledobject_controller.go b/controllers/keda/scaledobject_controller.go index 92c898e2f20..c480dc380c4 100755 --- a/controllers/keda/scaledobject_controller.go +++ b/controllers/keda/scaledobject_controller.go @@ -282,6 +282,11 @@ func (r *ScaledObjectReconciler) reconcileScaledObject(ctx context.Context, logg return "ScaledObject doesn't have correct triggers specification", err } + err = r.updateStatusWithTriggersAndAuthsTypes(ctx, logger, scaledObject) + if err != nil { + return "Cannot update ScaledObject status with triggers'types and authentications'types", err + } + // Create a new HPA or update existing one according to ScaledObject newHPACreated, err := r.ensureHPAForScaledObjectExists(ctx, logger, scaledObject, &gvkr) if err != nil {