Skip to content

Commit

Permalink
Treat spec.canary.analysis.template empty list as spec.canary.analysi…
Browse files Browse the repository at this point in the history
…s not set

Signed-off-by: Kevin Qian <[email protected]>
  • Loading branch information
kevinqian-db committed Mar 14, 2024
1 parent d510545 commit a6c76a2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rollout/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (c *rolloutContext) reconcilePostPromotionAnalysisRun() (*v1alpha1.Analysis

func (c *rolloutContext) reconcileBackgroundAnalysisRun() (*v1alpha1.AnalysisRun, error) {
currentAr := c.currentArs.CanaryBackground
if c.rollout.Spec.Strategy.Canary.Analysis == nil {
if c.rollout.Spec.Strategy.Canary.Analysis == nil || len(c.rollout.Spec.Strategy.Canary.Analysis.Templates) == 0 {
err := c.cancelAnalysisRuns([]*v1alpha1.AnalysisRun{currentAr})
return nil, err
}
Expand Down
42 changes: 42 additions & 0 deletions rollout/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2468,3 +2468,45 @@ func TestCreateAnalysisRunWithCustomAnalysisRunMetadataAndROCopyLabels(t *testin
assert.Equal(t, "testLabelValue", createdAr.Labels["testLabelKey"])
assert.Equal(t, "1234", createdAr.Labels["my-label"])
}

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

at := analysisTemplate("bar")
steps := []v1alpha1.CanaryStep{
{SetWeight: pointer.Int32Ptr(10)},
}

r1 := newCanaryRollout("foo", 1, nil, steps, pointer.Int32Ptr(1), intstr.FromInt(0), intstr.FromInt(1))
rs1 := newReplicaSetWithStatus(r1, 1, 1)
rs1PodHash := rs1.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]
r1 = updateCanaryRolloutStatus(r1, rs1PodHash, 1, 1, 1, false)
ar := analysisRun(at, v1alpha1.RolloutTypeStepLabel, r1)
r1.Status.Canary.CurrentBackgroundAnalysisRunStatus = &v1alpha1.RolloutAnalysisRunStatus{
Name: ar.Name,
Status: v1alpha1.AnalysisPhaseRunning,
}

r2 := bumpVersion(r1)
r2.Spec.Strategy.Canary.Analysis = &v1alpha1.RolloutAnalysisBackground{
RolloutAnalysis: v1alpha1.RolloutAnalysis{}, // No templates provided.
}
rs2 := newReplicaSetWithStatus(r2, 0, 0)

f.kubeobjects = append(f.kubeobjects, rs1, rs2)
f.replicaSetLister = append(f.replicaSetLister, rs1, rs2)
f.rolloutLister = append(f.rolloutLister, r2)
f.analysisTemplateLister = append(f.analysisTemplateLister, at)
f.analysisRunLister = append(f.analysisRunLister, ar)
f.objects = append(f.objects, r2, at, ar)

_ = f.expectPatchAnalysisRunAction(ar)
patchIndex := f.expectPatchRolloutAction(r2)
_ = f.expectUpdateReplicaSetAction(rs1)
f.run(getKey(r2, t))

patch := f.getPatchedRollout(patchIndex)

assert.Contains(t, patch, `"currentBackgroundAnalysisRunStatus":null`)
}

0 comments on commit a6c76a2

Please sign in to comment.