Skip to content

Commit

Permalink
scale from zero when minReplicaCount is > 0 (#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
zroubalik authored and ahmelsayed committed Jan 6, 2020
1 parent 76f4cf1 commit 8658859
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/handler/scale_deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ func (h *ScaleHandler) scaleDeployment(deployment *appsv1.Deployment, scaledObje

// Try to scale it down.
h.scaleDeploymentToZero(deployment, scaledObject)
} else if !isActive &&
scaledObject.Spec.MinReplicaCount != nil &&
*deployment.Spec.Replicas < *scaledObject.Spec.MinReplicaCount {
// there are no active triggers
// AND
// deployment replicas count is less than minimum replica count specified in ScaledObject
// Let's set deployment replicas count to correct value
*deployment.Spec.Replicas = *scaledObject.Spec.MinReplicaCount

err := h.updateDeployment(deployment)
if err == nil {
h.logger.Info("Successfully set Deployment replicas count to ScaledObject minReplicaCount", "Deployment.Namespace", deployment.GetNamespace(), "Deployment.Name", deployment.GetName(), "Deployment.Replicas", *deployment.Spec.Replicas)
}
} else if isActive {
// triggers are active, but we didn't need to scale (replica count > 0)
// Update LastActiveTime to now.
Expand Down

0 comments on commit 8658859

Please sign in to comment.