diff --git a/apis/keda/v1alpha1/scaledobject_types.go b/apis/keda/v1alpha1/scaledobject_types.go index e35ec931fc8..c2c670819ec 100644 --- a/apis/keda/v1alpha1/scaledobject_types.go +++ b/apis/keda/v1alpha1/scaledobject_types.go @@ -112,6 +112,7 @@ type Fallback struct { FailureThreshold int32 `json:"failureThreshold"` Replicas int32 `json:"replicas"` // +optional + // +kubebuilder:default=static // +kubebuilder:validation:Enum=static;useCurrentReplicasAsMinimum Behavior string `json:"behavior,omitempty"` } diff --git a/config/crd/bases/keda.sh_scaledobjects.yaml b/config/crd/bases/keda.sh_scaledobjects.yaml index 479fedef457..c6d7d4c6a5d 100644 --- a/config/crd/bases/keda.sh_scaledobjects.yaml +++ b/config/crd/bases/keda.sh_scaledobjects.yaml @@ -226,6 +226,10 @@ spec: description: Fallback is the spec for fallback options properties: behavior: + default: static + enum: + - static + - useCurrentReplicasAsMinimum type: string failureThreshold: format: int32 diff --git a/pkg/fallback/fallback.go b/pkg/fallback/fallback.go index 345372fef69..81b28157f32 100644 --- a/pkg/fallback/fallback.go +++ b/pkg/fallback/fallback.go @@ -111,12 +111,6 @@ func HasValidFallback(scaledObject *kedav1alpha1.ScaledObject) bool { func doFallback(scaledObject *kedav1alpha1.ScaledObject, metricSpec v2.MetricSpec, metricName string, currentReplicas int32, suppressedError error) []external_metrics.ExternalMetricValue { fallbackBehavior := scaledObject.Spec.Fallback.Behavior - - // Check if behavior is empty - if fallbackBehavior == "" { - fallbackBehavior = kedav1alpha1.FallbackBehaviorStatic - } - fallbackReplicas := int64(scaledObject.Spec.Fallback.Replicas) var replicas int64 diff --git a/pkg/scaling/executor/scale_scaledobjects.go b/pkg/scaling/executor/scale_scaledobjects.go index dea1a52d969..c4ee9324f40 100644 --- a/pkg/scaling/executor/scale_scaledobjects.go +++ b/pkg/scaling/executor/scale_scaledobjects.go @@ -207,12 +207,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) { fallbackBehavior := scaledObject.Spec.Fallback.Behavior - - // Check if behavior is empty - if fallbackBehavior == "" { - fallbackBehavior = kedav1alpha1.FallbackBehaviorStatic - } - fallbackReplicas := scaledObject.Spec.Fallback.Replicas switch fallbackBehavior {