Skip to content

Commit

Permalink
Merge pull request #1 from deliveryhero/fix-rollback-window-switch
Browse files Browse the repository at this point in the history
fix: guardrail traffic switch
  • Loading branch information
staffanselander authored Nov 25, 2024
2 parents 1e49b19 + adda5e4 commit c6599f1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions rollout/trafficrouting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -234,6 +235,12 @@ func (c *rolloutContext) reconcileTrafficRouting() error {
desiredWeight = weightutil.MaxTrafficWeight(c.rollout)
}
}

// Guardrail, which makes sure that we don't switch traffic before there's enough replicas.
if !c.checkReplicasAvailable(c.newRS, 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)
Expand Down Expand Up @@ -300,6 +307,24 @@ func (c *rolloutContext) reconcileTrafficRouting() error {
return nil
}

func (c *rolloutContext) checkReplicasAvailable(rs *appsv1.ReplicaSet, desiredWeight int32) bool {
if rs == nil {
return false
}

availableReplicas := rs.Status.AvailableReplicas
totalReplicas := *c.rollout.Spec.Replicas

desiredReplicas := (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 {
Expand Down

0 comments on commit c6599f1

Please sign in to comment.