Skip to content

Commit

Permalink
Add AddErrorConditionAfterErrorAnalysisRunBackground
Browse files Browse the repository at this point in the history
  • Loading branch information
dthomson25 committed Oct 25, 2019
1 parent 1d21245 commit b6f3385
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
57 changes: 56 additions & 1 deletion rollout/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ func TestPausedStepAfterInconclusiveAnalysisRun(t *testing.T) {
assert.Equal(t, calculatePatch(r2, fmt.Sprintf(expectedPatch, condition, v1alpha1.PauseReasonInconclusiveAnalysis, now)), patch)
}

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

Expand Down Expand Up @@ -668,6 +668,61 @@ func TestErrorConditionAfterErrorAnalysisRun(t *testing.T) {
assert.Equal(t, calculatePatch(r2, fmt.Sprintf(expectedPatch, condition)), patch)
}

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

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

r1 := newCanaryRollout("foo", 10, nil, steps, pointer.Int32Ptr(0), intstr.FromInt(0), intstr.FromInt(1))
r2 := bumpVersion(r1)
r2.Spec.Strategy.Canary.Analysis = &v1alpha1.RolloutAnalysisStep{
TemplateName: at.Name,
}
ar := analysisRun(at, v1alpha1.RolloutTypeBackgroundRunLabel, r2)
ar.Status = &v1alpha1.AnalysisRunStatus{
Status: v1alpha1.AnalysisStatusError,
MetricResults: []v1alpha1.MetricResult{{
Status: v1alpha1.AnalysisStatusError,
}},
}

rs1 := newReplicaSetWithStatus(r1, 9, 9)
rs2 := newReplicaSetWithStatus(r2, 1, 1)
f.kubeobjects = append(f.kubeobjects, rs1, rs2)
f.replicaSetLister = append(f.replicaSetLister, rs1, rs2)
rs1PodHash := rs1.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]

r2 = updateCanaryRolloutStatus(r2, rs1PodHash, 10, 1, 10, false)
r2.Status.Canary.CurrentBackgroundAnalysisRun = ar.Name

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)

patchIndex := f.expectPatchRolloutAction(r2)
f.run(getKey(r2, t))
patch := f.getPatchedRollout(patchIndex)
expectedPatch := `{
"status": {
"canary":{
"currentBackgroundAnalysisRun": null
},
"conditions": %s,
"abort": true
}
}`
condition := generateConditionsPatch(true, conditions.RolloutAnalysisRunFailedReason, r2, false)

assert.Equal(t, calculatePatch(r2, fmt.Sprintf(expectedPatch, condition)), patch)
}

func TestCancelAnalysisRunsWhenAborted(t *testing.T) {
f := newFixture(t)
defer f.Close()
Expand Down
5 changes: 3 additions & 2 deletions rollout/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,11 @@ func newProgressingCondition(reason string, resourceObj runtime.Object) (v1alpha
}
if reason == conditions.RolloutAnalysisRunFailedReason {
atName := ""
if resource.Spec.Strategy.Canary.Steps != nil && resource.Status.CurrentStepIndex != nil {
if resource.Spec.Strategy.Canary.Analysis != nil {
atName = resource.Spec.Strategy.Canary.Analysis.TemplateName
} else if resource.Spec.Strategy.Canary.Steps != nil && resource.Status.CurrentStepIndex != nil {
atName = resource.Spec.Strategy.Canary.Steps[*resource.Status.CurrentStepIndex].Analysis.TemplateName
}
//TODO(dthomson) Add support for parellel analysisRuns too
arName := fmt.Sprintf("%s-%s-%s-%s", resource.Name, atName, resource.Status.CurrentPodHash, MockGeneratedNameSuffix)
msg = fmt.Sprintf(conditions.RolloutAnalysisRunFailedMessage, arName, resource.Name)
status = corev1.ConditionFalse
Expand Down

0 comments on commit b6f3385

Please sign in to comment.