Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix error check in validation for AnalysisTemplates not found #1249

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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