Skip to content

Commit

Permalink
Merge pull request #1253 from andylibrian/scale-from-zero-use-hpa-min…
Browse files Browse the repository at this point in the history
…replicas

If HPA is set, it uses HPA minReplicas when scaling up the canary
  • Loading branch information
aryan9600 authored Aug 24, 2022
2 parents e65dfbb + 8b11551 commit ae4613f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/canary/deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,30 @@ func (c *DeploymentController) ScaleFromZero(cd *flaggerv1.Canary) error {
if primary.Spec.Replicas != nil && *primary.Spec.Replicas > 0 {
replicas = primary.Spec.Replicas
}
} else if cd.Spec.AutoscalerRef != nil {
if cd.Spec.AutoscalerRef.Kind == "HorizontalPodAutoscaler" {
hpa, err := c.kubeClient.AutoscalingV2().HorizontalPodAutoscalers(cd.Namespace).Get(context.TODO(), cd.Spec.AutoscalerRef.Name, metav1.GetOptions{})
if err == nil {
if hpa.Spec.MinReplicas != nil && *hpa.Spec.MinReplicas > 1 {
replicas = hpa.Spec.MinReplicas
}
} else {
// fallback to v2beta2
hpa, err := c.kubeClient.AutoscalingV2beta2().HorizontalPodAutoscalers(cd.Namespace).Get(context.TODO(), cd.Spec.AutoscalerRef.Name, metav1.GetOptions{})
if err == nil {
if hpa.Spec.MinReplicas != nil && *hpa.Spec.MinReplicas > 1 {
replicas = hpa.Spec.MinReplicas
}
}
}
} else if cd.Spec.AutoscalerRef.Kind == "ScaledObject" {
so, err := c.flaggerClient.KedaV1alpha1().ScaledObjects(cd.Namespace).Get(context.TODO(), cd.Spec.AutoscalerRef.Name, metav1.GetOptions{})
if err == nil {
if so.Spec.MinReplicaCount != nil && *so.Spec.MinReplicaCount > 1 {
replicas = so.Spec.MinReplicaCount
}
}
}
}
depCopy := dep.DeepCopy()
depCopy.Spec.Replicas = replicas
Expand Down

0 comments on commit ae4613f

Please sign in to comment.