Skip to content

Commit

Permalink
fix: update during setWeight: 100 could cause 503 errors
Browse files Browse the repository at this point in the history
Signed-off-by: Jesse Suen <[email protected]>
  • Loading branch information
jessesuen committed Sep 30, 2024
1 parent 4e44913 commit 36a8bf8
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 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)
}
}

// 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)
Expand Down Expand Up @@ -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)

Check failure on line 314 in rollout/trafficrouting.go

View workflow job for this annotation

GitHub Actions / Lint Go code

unnecessary conversion (unconvert)
totalReplicas := int32(*c.rollout.Spec.Replicas)

Check failure on line 315 in rollout/trafficrouting.go

View workflow job for this annotation

GitHub Actions / Lint Go code

unnecessary conversion (unconvert)

desiredReplicas := int32((desiredWeight * totalReplicas) / 100)

Check failure on line 317 in rollout/trafficrouting.go

View workflow job for this annotation

GitHub Actions / Lint Go code

unnecessary conversion (unconvert)
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 36a8bf8

Please sign in to comment.