mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
use min replicas set by autoscaler in ScaleFromZero if autoscaler is specified
Without this, the canary replicas are updated twice: to 1 replica then after a few seconds to the value of HPA minReplicas. In some cases, when updated to 1 replica (before updated by HPA controller to the minReplicas), it's considered ready: 1 of 1 (readyThreshold 100%), and the canary weight is advanced to receive traffic with less capacity than expected. Co-Authored-By: Joshua Gibeon <joshuagibeon7719@gmail.com> Co-authored-by: Sanskar Jaiswal <hey@aryan.lol> Signed-off-by: Andy Librian <andylibrian@gmail.com>
This commit is contained in:
co-authored by
Joshua Gibeon
Sanskar Jaiswal
parent
e65dfbb659
commit
8b1155123d
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user