Skip to content

Commit

Permalink
fix(canary): skip steps when in rollback window and rs is still active
Browse files Browse the repository at this point in the history
Resolve argoproj#2939

Signed-off-by: Andy Chen <[email protected]>
  • Loading branch information
yohanb authored and amazingandyyy committed Aug 28, 2023
1 parent 252e6ee commit 8a22b81
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 9 additions & 3 deletions rollout/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,19 @@ func (c *rolloutContext) syncRolloutStatusCanary() error {

if replicasetutil.PodTemplateOrStepsChanged(c.rollout, c.newRS) {
c.resetRolloutStatus(&newStatus)
if c.newRS != nil && c.rollout.Status.StableRS == replicasetutil.GetPodTemplateHash(c.newRS) {
if stepCount > 0 {
if c.newRS != nil && stepCount > 0 {
if c.rollout.Status.StableRS == replicasetutil.GetPodTemplateHash(c.newRS) {
// If we get here, we detected that we've moved back to the stable ReplicaSet
c.recorder.Eventf(c.rollout, record.EventOptions{EventReason: "SkipSteps"}, "Rollback to stable")
c.recorder.Eventf(c.rollout, record.EventOptions{EventReason: "SkipSteps"}, "Rollback to stable ReplicaSets")
newStatus.CurrentStepIndex = &stepCount
} else if c.isRollbackWithinWindow() && replicasetutil.IsActive(c.newRS) {
// Else if we get here we detected that we are within the rollback window
// we can skip steps and move back to the active ReplicaSet
c.recorder.Eventf(c.rollout, record.EventOptions{EventReason: "SkipSteps"}, "Rollback to active ReplicaSets within RollbackWindow")
newStatus.CurrentStepIndex = &stepCount
}
}

newStatus = c.calculateRolloutConditions(newStatus)
return c.persistRolloutStatus(&newStatus)
}
Expand Down
9 changes: 9 additions & 0 deletions utils/replicaset/replicaset.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,15 @@ func FindActiveOrLatest(newRS *appsv1.ReplicaSet, oldRSs []*appsv1.ReplicaSet) *
}
}

// IsActive returns if replica set is active (has, or at least ought to have pods).
func IsActive(rs *appsv1.ReplicaSet) bool {
if rs == nil {
return false
}

return len(controller.FilterActiveReplicaSets([]*appsv1.ReplicaSet{rs})) > 0
}

// GetReplicaCountForReplicaSets returns the sum of Replicas of the given replica sets.
func GetReplicaCountForReplicaSets(replicaSets []*appsv1.ReplicaSet) int32 {
totalReplicas := int32(0)
Expand Down

0 comments on commit 8a22b81

Please sign in to comment.