From 371c33b9fa3e79d12120e675aa97d8b26da5d899 Mon Sep 17 00:00:00 2001
From: Youssef Rabie <youssef.rabie@procore.com>
Date: Sat, 1 Feb 2025 23:46:36 +0200
Subject: [PATCH] fix: fix waiting to reach failureThreshold before fallback

Signed-off-by: Youssef Rabie <youssef.rabie@procore.com>
---
 pkg/scaling/executor/scale_executor.go      |  7 -------
 pkg/scaling/executor/scale_scaledobjects.go | 19 -------------------
 2 files changed, 26 deletions(-)

diff --git a/pkg/scaling/executor/scale_executor.go b/pkg/scaling/executor/scale_executor.go
index 05832f82a10..90e66eb6e10 100644
--- a/pkg/scaling/executor/scale_executor.go
+++ b/pkg/scaling/executor/scale_executor.go
@@ -125,10 +125,3 @@ func (e *scaleExecutor) setActiveCondition(ctx context.Context, logger logr.Logg
 	}
 	return e.setCondition(ctx, logger, object, status, reason, message, active)
 }
-
-func (e *scaleExecutor) setFallbackCondition(ctx context.Context, logger logr.Logger, object interface{}, status metav1.ConditionStatus, reason string, message string) error {
-	fallback := func(conditions kedav1alpha1.Conditions, status metav1.ConditionStatus, reason string, message string) {
-		conditions.SetFallbackCondition(status, reason, message)
-	}
-	return e.setCondition(ctx, logger, object, status, reason, message, fallback)
-}
diff --git a/pkg/scaling/executor/scale_scaledobjects.go b/pkg/scaling/executor/scale_scaledobjects.go
index ee1284fb8e5..ed1beede7f0 100644
--- a/pkg/scaling/executor/scale_scaledobjects.go
+++ b/pkg/scaling/executor/scale_scaledobjects.go
@@ -160,13 +160,6 @@ func (e *scaleExecutor) RequestScale(ctx context.Context, scaledObject *kedav1al
 	} else {
 		// isActive == false
 		switch {
-		case isError && scaledObject.Spec.Fallback != nil && scaledObject.Spec.Fallback.Replicas != 0:
-			// there are no active triggers, but a scaler responded with an error
-			// AND
-			// there is a fallback replicas count defined
-
-			// Scale to the fallback replicas count
-			e.doFallbackScaling(ctx, scaledObject, currentScale, logger, currentReplicas)
 		case isError && scaledObject.Spec.Fallback == nil:
 			// there are no active triggers, but a scaler responded with an error
 			// AND
@@ -230,18 +223,6 @@ func (e *scaleExecutor) RequestScale(ctx context.Context, scaledObject *kedav1al
 	}
 }
 
-func (e *scaleExecutor) doFallbackScaling(ctx context.Context, scaledObject *kedav1alpha1.ScaledObject, currentScale *autoscalingv1.Scale, logger logr.Logger, currentReplicas int32) {
-	_, err := e.updateScaleOnScaleTarget(ctx, scaledObject, currentScale, scaledObject.Spec.Fallback.Replicas)
-	if err == nil {
-		logger.Info("Successfully set ScaleTarget replicas count to ScaledObject fallback.replicas",
-			"Original Replicas Count", currentReplicas,
-			"New Replicas Count", scaledObject.Spec.Fallback.Replicas)
-	}
-	if e := e.setFallbackCondition(ctx, logger, scaledObject, metav1.ConditionTrue, "FallbackExists", "At least one trigger is falling back on this scaled object"); e != nil {
-		logger.Error(e, "Error setting fallback condition")
-	}
-}
-
 // An object will be scaled down to 0 only if it's passed its cooldown period
 // or if LastActiveTime is nil
 func (e *scaleExecutor) scaleToZeroOrIdle(ctx context.Context, logger logr.Logger, scaledObject *kedav1alpha1.ScaledObject, scale *autoscalingv1.Scale) {