diff --git a/rollout/trafficrouting.go b/rollout/trafficrouting.go index 3ed2564760..0f043080fe 100644 --- a/rollout/trafficrouting.go +++ b/rollout/trafficrouting.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/argoproj/argo-rollouts/utils/annotations" + appsv1 "k8s.io/api/apps/v1" "github.com/argoproj/argo-rollouts/rollout/trafficrouting/plugin" @@ -234,6 +235,12 @@ func (c *rolloutContext) reconcileTrafficRouting() error { desiredWeight = weightutil.MaxTrafficWeight(c.rollout) } } + + // for checking whether required number of replicas are there or not in stable replicaset. + if !c.checkReplicasAvailable(c.stableRS, 100-desiredWeight) { + return nil + } + // We need to check for revision > 1 because when we first install the rollout we run step 0 this prevents that. // There is a bigger fix needed for the reasons on why we run step 0 on rollout install, that needs to be explored. revision, revisionFound := annotations.GetRevisionAnnotation(c.rollout) @@ -300,6 +307,22 @@ func (c *rolloutContext) reconcileTrafficRouting() error { return nil } +func (c *rolloutContext) checkReplicasAvailable(rs *appsv1.ReplicaSet, desiredWeight int32) bool { + if rs == nil { + return false + } + availableReplicas := int32(rs.Status.AvailableReplicas) + totalReplicas := int32(*c.rollout.Spec.Replicas) + + desiredReplicas := int32((desiredWeight * totalReplicas) / 100) + if availableReplicas < desiredReplicas { + c.log.Infof("ReplicaSet '%s' has %d available replicas, waiting for %d", rs.Name, availableReplicas, desiredReplicas) + return false + } + + return true +} + // calculateDesiredWeightOnAbortOrStableRollback returns the desired weight to use when we are either // aborting, or rolling back to stable RS. func (c *rolloutContext) calculateDesiredWeightOnAbortOrStableRollback() int32 {