diff --git a/rollout/analysis.go b/rollout/analysis.go index 7bb0d47f1f..f23f680ce0 100644 --- a/rollout/analysis.go +++ b/rollout/analysis.go @@ -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) diff --git a/rollout/analysis_test.go b/rollout/analysis_test.go index 0f1d1e9aef..fa7fdc5b96 100644 --- a/rollout/analysis_test.go +++ b/rollout/analysis_test.go @@ -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()