Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ScaledObject parameter StartReplicaCount to scale from 0 to N #5493

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Here is an overview of all new **experimental** features:
### Improvements

- **General**: Add OPENTELEMETRY flag in e2e test YAML ([#5375](https://github.com/kedacore/keda/issues/5375))
- **General**: Add startReplicaCount parameter to ScaledObject for scaling from 0 to N replicas

### Fixes

Expand Down
7 changes: 7 additions & 0 deletions apis/keda/v1alpha1/scaledobject_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
// +kubebuilder:printcolumn:name="ScaleTargetName",type="string",JSONPath=".spec.scaleTargetRef.name"
// +kubebuilder:printcolumn:name="Min",type="integer",JSONPath=".spec.minReplicaCount"
// +kubebuilder:printcolumn:name="Max",type="integer",JSONPath=".spec.maxReplicaCount"
// +kubebuilder:printcolumn:name="Start",type="integer",JSONPath=".spec.startReplicaCount"
// +kubebuilder:printcolumn:name="Triggers",type="string",JSONPath=".spec.triggers[*].type"
// +kubebuilder:printcolumn:name="Authentication",type="string",JSONPath=".spec.triggers[*].authenticationRef.name"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status"
Expand Down Expand Up @@ -95,6 +96,8 @@ type ScaledObjectSpec struct {
// +optional
MaxReplicaCount *int32 `json:"maxReplicaCount,omitempty"`
// +optional
StartReplicaCount *int32 `json:"startReplicaCount,omitempty"`
// +optional
Advanced *AdvancedConfig `json:"advanced,omitempty"`

Triggers []ScaleTriggers `json:"triggers"`
Expand Down Expand Up @@ -256,6 +259,10 @@ func CheckReplicaCountBoundsAreValid(scaledObject *ScaledObject) error {
}
max := scaledObject.GetHPAMaxReplicas()

if scaledObject.Spec.StartReplicaCount != nil && (*scaledObject.Spec.StartReplicaCount > max || *scaledObject.Spec.StartReplicaCount < min) {
return fmt.Errorf("StartReplicaCount=%d must be less than or equal to MaxReplicaCount=%d and greater than or equal to MinReplicaCount=%d", *scaledObject.Spec.StartReplicaCount, max, min)
}

if min > max {
return fmt.Errorf("MinReplicaCount=%d must be less than MaxReplicaCount=%d", min, max)
}
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/keda.sh_scaledobjects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ spec:
- jsonPath: .spec.maxReplicaCount
name: Max
type: integer
- jsonPath: .spec.startReplicaCount
name: Start
type: integer
- jsonPath: .spec.triggers[*].type
name: Triggers
type: string
Expand Down Expand Up @@ -244,6 +247,9 @@ spec:
minReplicaCount:
format: int32
type: integer
startReplicaCount:
format: int32
type: integer
pollingInterval:
format: int32
type: integer
Expand Down
4 changes: 3 additions & 1 deletion pkg/scaling/executor/scale_scaledobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ func (e *scaleExecutor) scaleToZeroOrIdle(ctx context.Context, logger logr.Logge

func (e *scaleExecutor) scaleFromZeroOrIdle(ctx context.Context, logger logr.Logger, scaledObject *kedav1alpha1.ScaledObject, scale *autoscalingv1.Scale) {
var replicas int32
if scaledObject.Spec.MinReplicaCount != nil && *scaledObject.Spec.MinReplicaCount > 0 {
if scaledObject.Spec.StartReplicaCount != nil && scaledObject.Spec.MinReplicaCount != nil && *scaledObject.Spec.StartReplicaCount > *scaledObject.Spec.MinReplicaCount {
replicas = *scaledObject.Spec.StartReplicaCount
} else if scaledObject.Spec.MinReplicaCount != nil && *scaledObject.Spec.MinReplicaCount > 0 {
replicas = *scaledObject.Spec.MinReplicaCount
} else {
replicas = 1
Expand Down
Loading