Skip to content

Commit

Permalink
fix: Fix error check in validation for AnalysisTemplates not found (#…
Browse files Browse the repository at this point in the history
…1249)

Signed-off-by: khhirani <[email protected]>
  • Loading branch information
khhirani authored Jun 3, 2021
1 parent ccff157 commit c68f3df
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rollout/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,10 @@ func (c *rolloutContext) getReferencedRolloutAnalyses() (*[]validation.AnalysisT
for i, step := range canary.Steps {
if step.Analysis != nil {
templates, err := c.getReferencedAnalysisTemplates(c.rollout, step.Analysis, validation.InlineAnalysis, i)
templates.Args = step.Analysis.Args
if err != nil {
return nil, err
}
templates.Args = step.Analysis.Args
analysisTemplates = append(analysisTemplates, *templates)
}
}
Expand Down
65 changes: 64 additions & 1 deletion rollout/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,70 @@ func newInvalidSpecCondition(reason string, resourceObj runtime.Object, optional
return condition, string(conditionBytes)
}

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

rolloutAnalysisFail := v1alpha1.RolloutAnalysis{
Templates: []v1alpha1.RolloutAnalysisTemplate{{
TemplateName: "does-not-exist",
ClusterScope: false,
}},
}

t.Run("blueGreen pre-promotion analysis - fail", func(t *testing.T) {
r := newBlueGreenRollout("rollout", 1, nil, "active-service", "preview-service")
r.Spec.Strategy.BlueGreen.PrePromotionAnalysis = &rolloutAnalysisFail
c, _, _ := f.newController(noResyncPeriodFunc)
roCtx, err := c.newRolloutContext(r)
assert.NoError(t, err)
_, err = roCtx.getReferencedRolloutAnalyses()
assert.NotNil(t, err)
msg := "spec.strategy.blueGreen.prePromotionAnalysis.templates: Invalid value: \"does-not-exist\": AnalysisTemplate 'does-not-exist' not found"
assert.Equal(t, msg, err.Error())
})

t.Run("blueGreen post-promotion analysis - fail", func(t *testing.T) {
r := newBlueGreenRollout("rollout", 1, nil, "active-service", "preview-service")
r.Spec.Strategy.BlueGreen.PostPromotionAnalysis = &rolloutAnalysisFail
c, _, _ := f.newController(noResyncPeriodFunc)
roCtx, err := c.newRolloutContext(r)
assert.NoError(t, err)
_, err = roCtx.getReferencedRolloutAnalyses()
assert.NotNil(t, err)
msg := "spec.strategy.blueGreen.postPromotionAnalysis.templates: Invalid value: \"does-not-exist\": AnalysisTemplate 'does-not-exist' not found"
assert.Equal(t, msg, err.Error())
})

t.Run("canary analysis - fail", func(t *testing.T) {
r := newCanaryRollout("rollout-canary", 1, nil, nil, int32Ptr(0), intstr.FromInt(0), intstr.FromInt(1))
r.Spec.Strategy.Canary.Analysis = &v1alpha1.RolloutAnalysisBackground{
RolloutAnalysis: rolloutAnalysisFail,
}
c, _, _ := f.newController(noResyncPeriodFunc)
roCtx, err := c.newRolloutContext(r)
assert.NoError(t, err)
_, err = roCtx.getReferencedRolloutAnalyses()
assert.NotNil(t, err)
msg := "spec.strategy.canary.analysis.templates: Invalid value: \"does-not-exist\": AnalysisTemplate 'does-not-exist' not found"
assert.Equal(t, msg, err.Error())
})

t.Run("canary step analysis - fail", func(t *testing.T) {
canarySteps := []v1alpha1.CanaryStep{{
Analysis: &rolloutAnalysisFail,
}}
r := newCanaryRollout("rollout-canary", 1, nil, canarySteps, int32Ptr(0), intstr.FromInt(0), intstr.FromInt(1))
c, _, _ := f.newController(noResyncPeriodFunc)
roCtx, err := c.newRolloutContext(r)
assert.NoError(t, err)
_, err = roCtx.getReferencedRolloutAnalyses()
assert.NotNil(t, err)
msg := "spec.strategy.canary.steps[0].analysis.templates: Invalid value: \"does-not-exist\": AnalysisTemplate 'does-not-exist' not found"
assert.Equal(t, msg, err.Error())
})
}

func TestGetReferencedAnalysisTemplate(t *testing.T) {
f := newFixture(t)
defer f.Close()
Expand All @@ -1447,7 +1511,6 @@ func TestGetReferencedAnalysisTemplate(t *testing.T) {
ClusterScope: true,
}},
}
defer f.Close()

t.Run("get referenced analysisTemplate - fail", func(t *testing.T) {
c, _, _ := f.newController(noResyncPeriodFunc)
Expand Down

0 comments on commit c68f3df

Please sign in to comment.