Skip to content

Commit 4392995

Browse files
authored
Add another scenario to e2e test (#1756)
* Add another scenario to e2e test * Initialise Status in the same order as the plan * Fix getters to return correct reference Signed-off-by: Andreas Neumann <[email protected]>
1 parent 3c56293 commit 4392995

File tree

4 files changed

+71
-10
lines changed

4 files changed

+71
-10
lines changed

pkg/apis/kudo/v1beta1/instance_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ func (s *StepStatus) SetWithMessage(status ExecutionStatus, message string) {
118118

119119
// Step returns the StepStatus with the given name, or nil if no such step status exists
120120
func (s *PhaseStatus) Step(name string) *StepStatus {
121-
for _, stepStatus := range s.Steps {
121+
for i, stepStatus := range s.Steps {
122122
if stepStatus.Name == name {
123-
return &stepStatus
123+
return &s.Steps[i]
124124
}
125125
}
126126
return nil
@@ -138,9 +138,9 @@ func (s *PhaseStatus) SetWithMessage(status ExecutionStatus, message string) {
138138

139139
// Step returns the PhaseStatus with the given name, or nil if no such phase status exists
140140
func (s *PlanStatus) Phase(name string) *PhaseStatus {
141-
for _, phaseStatus := range s.Phases {
141+
for i, phaseStatus := range s.Phases {
142142
if phaseStatus.Name == name {
143-
return &phaseStatus
143+
return &s.Phases[i]
144144
}
145145
}
146146
return nil

pkg/controller/instance/instance_controller.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -540,26 +540,37 @@ func ensurePlanStatusInitialized(i *kudoapi.Instance, ov *kudoapi.OperatorVersio
540540
Phases: make([]kudoapi.PhaseStatus, 0),
541541
}
542542
}
543+
// We fully rebuild the phase status here to make sure that newly
544+
// added phases have a status in the correct order
545+
newPhaseStatus := make([]kudoapi.PhaseStatus, 0)
543546
for _, phase := range plan.Phases {
544547
phaseStatus := planStatus.Phase(phase.Name)
545548
if phaseStatus == nil {
546-
planStatus.Phases = append(planStatus.Phases, kudoapi.PhaseStatus{
549+
phaseStatus = &kudoapi.PhaseStatus{
547550
Name: phase.Name,
548551
Status: kudoapi.ExecutionNeverRun,
549552
Steps: make([]kudoapi.StepStatus, 0),
550-
})
551-
phaseStatus = &planStatus.Phases[len(planStatus.Phases)-1]
553+
}
552554
}
555+
556+
// Same here, full rebuild of the slice, so newly added steps
557+
// have a matching status
558+
newStepStatus := make([]kudoapi.StepStatus, 0)
553559
for _, step := range phase.Steps {
554560
stepStatus := phaseStatus.Step(step.Name)
555561
if stepStatus == nil {
556-
phaseStatus.Steps = append(phaseStatus.Steps, kudoapi.StepStatus{
562+
stepStatus = &kudoapi.StepStatus{
557563
Name: step.Name,
558564
Status: kudoapi.ExecutionNeverRun,
559-
})
565+
}
560566
}
567+
newStepStatus = append(newStepStatus, *stepStatus)
561568
}
569+
phaseStatus.Steps = newStepStatus
570+
newPhaseStatus = append(newPhaseStatus, *phaseStatus)
562571
}
572+
planStatus.Phases = newPhaseStatus
573+
563574
// We might have updated the plan status, so set it just to make sure
564575
i.Status.PlanStatus[planName] = planStatus
565576
}

pkg/controller/instance/instance_controller_test.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ func Test_ensurePlanStatusInitialized(t *testing.T) {
577577
},
578578
{
579579
name: "a new phase is correctly initialized",
580-
i: instance,
580+
i: instance.DeepCopy(),
581581
ov: func() *kudoapi.OperatorVersion {
582582
modifiedOv := ov.DeepCopy()
583583
pln := modifiedOv.Spec.Plans["deploy"]
@@ -626,6 +626,48 @@ func Test_ensurePlanStatusInitialized(t *testing.T) {
626626
},
627627
},
628628
},
629+
{
630+
name: "a new step is correctly initialized",
631+
i: instance.DeepCopy(),
632+
ov: func() *kudoapi.OperatorVersion {
633+
modifiedOv := ov.DeepCopy()
634+
pln := modifiedOv.Spec.Plans["deploy"]
635+
pln.Phases[0].Steps = append([]kudoapi.Step{
636+
{
637+
Name: "additionalstep",
638+
Tasks: []string{},
639+
},
640+
}, pln.Phases[0].Steps...)
641+
modifiedOv.Spec.Plans["deploy"] = pln
642+
return modifiedOv
643+
}(),
644+
want: kudoapi.InstanceStatus{
645+
PlanStatus: map[string]kudoapi.PlanStatus{
646+
"deploy": {
647+
Name: "deploy",
648+
Status: kudoapi.ExecutionNeverRun,
649+
UID: "",
650+
Phases: []kudoapi.PhaseStatus{
651+
{
652+
Name: "phase",
653+
Status: kudoapi.ExecutionNeverRun,
654+
Steps: []kudoapi.StepStatus{
655+
{
656+
Name: "additionalstep",
657+
Status: kudoapi.ExecutionNeverRun,
658+
},
659+
{
660+
Name: "step",
661+
Status: kudoapi.ExecutionNeverRun,
662+
},
663+
},
664+
},
665+
},
666+
},
667+
"backup": backupStatus,
668+
},
669+
},
670+
},
629671
}
630672

631673
for _, tt := range tests {

test/e2e/upgrade/first-operator-v2/operator.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ tasks:
1818
spec:
1919
resources:
2020
- configmap.yaml
21+
- name: newstep
22+
kind: Apply
23+
spec:
24+
resources:
25+
- configmap.yaml
2126
plans:
2227
deploy:
2328
strategy: serial
@@ -31,6 +36,9 @@ plans:
3136
- name: main
3237
strategy: parallel
3338
steps:
39+
- name: prependstep
40+
tasks:
41+
- newstep
3442
- name: everything
3543
tasks:
3644
- app

0 commit comments

Comments
 (0)