Skip to content

Commit

Permalink
fix(analysis): Take RollbackWindow into account when Reconciling Anal…
Browse files Browse the repository at this point in the history
…ysis Runs. Fixes argoproj#3669 (argoproj#3670)

* Ensure that BackgroundAnalysisRun does not run when rolling back within RollbackWindow

Signed-off-by: Alex Dunn <[email protected]>

* Fix linting

Signed-off-by: Alex Dunn <[email protected]>

---------

Signed-off-by: Alex Dunn <[email protected]>
  • Loading branch information
Psukhe authored Jun 27, 2024
1 parent f21956c commit 243ea91
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rollout/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ func (c *rolloutContext) reconcileAnalysisRuns() error {
isAborted := c.pauseContext.IsAborted()
rollbackToScaleDownDelay := replicasetutil.HasScaleDownDeadline(c.newRS)
initialDeploy := c.rollout.Status.StableRS == ""
if isAborted || c.rollout.Status.PromoteFull || rollbackToScaleDownDelay || initialDeploy {
c.log.Infof("Skipping analysis: isAborted: %v, promoteFull: %v, rollbackToScaleDownDelay: %v, initialDeploy: %v", isAborted, c.rollout.Status.PromoteFull, rollbackToScaleDownDelay, initialDeploy)
isRollbackWithinWindow := c.isRollbackWithinWindow()
if isAborted || c.rollout.Status.PromoteFull || rollbackToScaleDownDelay || initialDeploy || isRollbackWithinWindow {
c.log.Infof("Skipping analysis: isAborted: %v, promoteFull: %v, rollbackToScaleDownDelay: %v, initialDeploy: %v, isRollbackWithinWindow: %v", isAborted, c.rollout.Status.PromoteFull, rollbackToScaleDownDelay, initialDeploy, isRollbackWithinWindow)
allArs := append(c.currentArs.ToArray(), c.otherArs...)
c.SetCurrentAnalysisRuns(c.currentArs)
return c.cancelAnalysisRuns(allArs)
Expand Down
41 changes: 41 additions & 0 deletions rollout/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,47 @@ func TestDoNotCreateBackgroundAnalysisRunOnNewCanaryRolloutStableRSEmpty(t *test
f.run(getKey(r1, t))
}

func TestDoNotCreateBackgroundAnalysisRunWhenWithinRollbackWindow(t *testing.T) {
f := newFixture(t)
defer f.Close()

at := analysisTemplate("bar")

r1 := newCanaryRollout("foo", 1, nil, nil, pointer.Int32Ptr(0), intstr.FromInt(0), intstr.FromInt(1))
r1.Spec.Strategy.Canary.Analysis = &v1alpha1.RolloutAnalysisBackground{
RolloutAnalysis: v1alpha1.RolloutAnalysis{
Templates: []v1alpha1.AnalysisTemplateRef{
{
TemplateName: at.Name,
},
},
},
}
r1.Spec.RollbackWindow = &v1alpha1.RollbackWindowSpec{Revisions: 1}

r2 := bumpVersion(r1)
rs1 := newReplicaSetWithStatus(r1, 1, 1)
rs2 := newReplicaSetWithStatus(r2, 0, 0)

rs2.CreationTimestamp = timeutil.MetaTime(time.Now().Add(-1 * time.Hour))
rs1.CreationTimestamp = timeutil.MetaNow()

f.kubeobjects = append(f.kubeobjects, rs1, rs2)
f.replicaSetLister = append(f.replicaSetLister, rs1, rs2)

rs1PodHash := rs1.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]

r2 = updateCanaryRolloutStatus(r2, rs1PodHash, 1, 0, 1, false)

f.rolloutLister = append(f.rolloutLister, r2)
f.analysisTemplateLister = append(f.analysisTemplateLister, at)
f.objects = append(f.objects, r2, at)

f.expectUpdateReplicaSetAction(rs2)
f.expectPatchRolloutAction(r2)
f.run(getKey(r2, t))
}

func TestCreatePrePromotionAnalysisRun(t *testing.T) {
f := newFixture(t)
defer f.Close()
Expand Down

0 comments on commit 243ea91

Please sign in to comment.