Skip to content

Commit c68f3df

Browse files
authored
fix: Fix error check in validation for AnalysisTemplates not found (argoproj#1249)
Signed-off-by: khhirani <[email protected]>
1 parent ccff157 commit c68f3df

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

rollout/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,10 @@ func (c *rolloutContext) getReferencedRolloutAnalyses() (*[]validation.AnalysisT
654654
for i, step := range canary.Steps {
655655
if step.Analysis != nil {
656656
templates, err := c.getReferencedAnalysisTemplates(c.rollout, step.Analysis, validation.InlineAnalysis, i)
657-
templates.Args = step.Analysis.Args
658657
if err != nil {
659658
return nil, err
660659
}
660+
templates.Args = step.Analysis.Args
661661
analysisTemplates = append(analysisTemplates, *templates)
662662
}
663663
}

rollout/controller_test.go

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,70 @@ func newInvalidSpecCondition(reason string, resourceObj runtime.Object, optional
14371437
return condition, string(conditionBytes)
14381438
}
14391439

1440+
func TestGetReferencedAnalyses(t *testing.T) {
1441+
f := newFixture(t)
1442+
defer f.Close()
1443+
1444+
rolloutAnalysisFail := v1alpha1.RolloutAnalysis{
1445+
Templates: []v1alpha1.RolloutAnalysisTemplate{{
1446+
TemplateName: "does-not-exist",
1447+
ClusterScope: false,
1448+
}},
1449+
}
1450+
1451+
t.Run("blueGreen pre-promotion analysis - fail", func(t *testing.T) {
1452+
r := newBlueGreenRollout("rollout", 1, nil, "active-service", "preview-service")
1453+
r.Spec.Strategy.BlueGreen.PrePromotionAnalysis = &rolloutAnalysisFail
1454+
c, _, _ := f.newController(noResyncPeriodFunc)
1455+
roCtx, err := c.newRolloutContext(r)
1456+
assert.NoError(t, err)
1457+
_, err = roCtx.getReferencedRolloutAnalyses()
1458+
assert.NotNil(t, err)
1459+
msg := "spec.strategy.blueGreen.prePromotionAnalysis.templates: Invalid value: \"does-not-exist\": AnalysisTemplate 'does-not-exist' not found"
1460+
assert.Equal(t, msg, err.Error())
1461+
})
1462+
1463+
t.Run("blueGreen post-promotion analysis - fail", func(t *testing.T) {
1464+
r := newBlueGreenRollout("rollout", 1, nil, "active-service", "preview-service")
1465+
r.Spec.Strategy.BlueGreen.PostPromotionAnalysis = &rolloutAnalysisFail
1466+
c, _, _ := f.newController(noResyncPeriodFunc)
1467+
roCtx, err := c.newRolloutContext(r)
1468+
assert.NoError(t, err)
1469+
_, err = roCtx.getReferencedRolloutAnalyses()
1470+
assert.NotNil(t, err)
1471+
msg := "spec.strategy.blueGreen.postPromotionAnalysis.templates: Invalid value: \"does-not-exist\": AnalysisTemplate 'does-not-exist' not found"
1472+
assert.Equal(t, msg, err.Error())
1473+
})
1474+
1475+
t.Run("canary analysis - fail", func(t *testing.T) {
1476+
r := newCanaryRollout("rollout-canary", 1, nil, nil, int32Ptr(0), intstr.FromInt(0), intstr.FromInt(1))
1477+
r.Spec.Strategy.Canary.Analysis = &v1alpha1.RolloutAnalysisBackground{
1478+
RolloutAnalysis: rolloutAnalysisFail,
1479+
}
1480+
c, _, _ := f.newController(noResyncPeriodFunc)
1481+
roCtx, err := c.newRolloutContext(r)
1482+
assert.NoError(t, err)
1483+
_, err = roCtx.getReferencedRolloutAnalyses()
1484+
assert.NotNil(t, err)
1485+
msg := "spec.strategy.canary.analysis.templates: Invalid value: \"does-not-exist\": AnalysisTemplate 'does-not-exist' not found"
1486+
assert.Equal(t, msg, err.Error())
1487+
})
1488+
1489+
t.Run("canary step analysis - fail", func(t *testing.T) {
1490+
canarySteps := []v1alpha1.CanaryStep{{
1491+
Analysis: &rolloutAnalysisFail,
1492+
}}
1493+
r := newCanaryRollout("rollout-canary", 1, nil, canarySteps, int32Ptr(0), intstr.FromInt(0), intstr.FromInt(1))
1494+
c, _, _ := f.newController(noResyncPeriodFunc)
1495+
roCtx, err := c.newRolloutContext(r)
1496+
assert.NoError(t, err)
1497+
_, err = roCtx.getReferencedRolloutAnalyses()
1498+
assert.NotNil(t, err)
1499+
msg := "spec.strategy.canary.steps[0].analysis.templates: Invalid value: \"does-not-exist\": AnalysisTemplate 'does-not-exist' not found"
1500+
assert.Equal(t, msg, err.Error())
1501+
})
1502+
}
1503+
14401504
func TestGetReferencedAnalysisTemplate(t *testing.T) {
14411505
f := newFixture(t)
14421506
defer f.Close()
@@ -1447,7 +1511,6 @@ func TestGetReferencedAnalysisTemplate(t *testing.T) {
14471511
ClusterScope: true,
14481512
}},
14491513
}
1450-
defer f.Close()
14511514

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

0 commit comments

Comments
 (0)