Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: guardrail traffic switch #1

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading