Skip to content

Commit

Permalink
Bugfix: IntegrationTest TestRestartController (#1313)
Browse files Browse the repository at this point in the history
Signed-off-by: Ken Sipe <kensipe@gmail.com>
  • Loading branch information
kensipe authored Jan 28, 2020
1 parent 8b67df5 commit 8df525a
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/kudo/v1beta1/instance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type PlanStatus struct {
Status ExecutionStatus `json:"status,omitempty"`
Message string `json:"message,omitempty"` // more verbose explanation of the status, e.g. a detailed error message
// +nullable
LastFinishedRun metav1.Time `json:"lastFinishedRun,omitempty"`
LastFinishedRun *metav1.Time `json:"lastFinishedRun,omitempty"`
Phases []PhaseStatus `json:"phases,omitempty"`
UID apimachinerytypes.UID `json:"uid,omitempty"`
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/kudo/v1beta1/instance_types_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (i *Instance) PlanStatus(plan string) *PlanStatus {

// wasRunAfter returns true if p1 was run after p2
func wasRunAfter(p1 PlanStatus, p2 PlanStatus) bool {
if p1.Status == ExecutionNeverRun || p2.Status == ExecutionNeverRun {
if p1.Status == ExecutionNeverRun || p2.Status == ExecutionNeverRun || p1.LastFinishedRun == nil || p2.LastFinishedRun == nil {
return false
}
return p1.LastFinishedRun.Time.After(p2.LastFinishedRun.Time)
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/kudo/v1beta1/instance_types_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ func TestGetLastExecutedPlanStatus(t *testing.T) {
"test": {
Status: ExecutionComplete,
Name: "test",
LastFinishedRun: metav1.Time{Time: testTime},
LastFinishedRun: &metav1.Time{Time: testTime},
Phases: []PhaseStatus{{Name: "phase", Status: ExecutionComplete, Steps: []StepStatus{{Status: ExecutionComplete, Name: "step"}}}},
},
"test2": {
Status: ExecutionComplete,
Name: "test2",
LastFinishedRun: metav1.Time{Time: testTime.Add(time.Hour)},
LastFinishedRun: &metav1.Time{Time: testTime.Add(time.Hour)},
Phases: []PhaseStatus{{Name: "phase", Status: ExecutionComplete, Steps: []StepStatus{{Status: ExecutionComplete, Name: "step"}}}},
}}, "test2"},
}
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestInstance_ResetPlanStatus(t *testing.T) {
"deploy": {
Status: ExecutionInProgress,
Name: "deploy",
LastFinishedRun: metav1.Time{Time: testTime},
LastFinishedRun: &metav1.Time{Time: testTime},
UID: testUUID,
Phases: []PhaseStatus{{Name: "phase", Status: ExecutionInProgress, Steps: []StepStatus{{Status: ExecutionInProgress, Name: "step"}}}},
},
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestInstance_ResetPlanStatus(t *testing.T) {
"deploy": {
Status: ExecutionPending,
Name: "deploy",
LastFinishedRun: metav1.Time{Time: testTime},
LastFinishedRun: &metav1.Time{Time: testTime},
UID: testUUID,
Phases: []PhaseStatus{{Name: "phase", Status: ExecutionPending, Steps: []StepStatus{{Status: ExecutionPending, Name: "step"}}}},
},
Expand Down
5 changes: 4 additions & 1 deletion pkg/apis/kudo/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/controller/instance/instance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestRestartController(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "foo-operator", Namespace: "default"},
TypeMeta: metav1.TypeMeta{Kind: "OperatorVersion", APIVersion: "kudo.dev/v1beta1"},
Spec: v1beta1.OperatorVersionSpec{
Plans: map[string]v1beta1.Plan{"deploy": {}, "update": {}},
Plans: map[string]v1beta1.Plan{"deploy": {Phases: []v1beta1.Phase{}}, "update": {Phases: []v1beta1.Phase{}}},
Parameters: []v1beta1.Parameter{
{
Name: "param",
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/workflow/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func Execute(pl *ActivePlan, em *engine.Metadata, c client.Client, enh renderer.
if phasesLeft == 0 {
log.Printf("PlanExecution: %s/%s all phases of the plan %s are ready", em.InstanceNamespace, em.InstanceName, pl.Name)
planStatus.Set(v1beta1.ExecutionComplete)
planStatus.LastFinishedRun = v1.Time{Time: currentTime}
planStatus.LastFinishedRun = &v1.Time{Time: currentTime}
}

return planStatus, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/engine/workflow/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestExecutePlan(t *testing.T) {
metadata: meta,
expectedStatus: &v1beta1.PlanStatus{
Status: v1beta1.ExecutionComplete,
LastFinishedRun: v1.Time{Time: timeNow},
LastFinishedRun: &v1.Time{Time: timeNow},
Name: "test",
Phases: []v1beta1.PhaseStatus{{Name: "phase", Status: v1beta1.ExecutionComplete, Steps: []v1beta1.StepStatus{{Status: v1beta1.ExecutionComplete, Name: "step"}}}},
},
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestExecutePlan(t *testing.T) {
metadata: meta,
expectedStatus: &v1beta1.PlanStatus{
Status: v1beta1.ExecutionComplete,
LastFinishedRun: v1.Time{Time: timeNow},
LastFinishedRun: &v1.Time{Time: timeNow},
Name: "test",
Phases: []v1beta1.PhaseStatus{{Name: "phase", Status: v1beta1.ExecutionComplete, Steps: []v1beta1.StepStatus{{Status: v1beta1.ExecutionComplete, Name: "step"}}}},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/kudoctl/cmd/plan/plan_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func planHistory(options *Options, settings *env.Settings) error {
for _, p := range instance.Status.PlanStatus {
msg := "never run" // this is for the cases when status was not yet populated

if !p.LastFinishedRun.IsZero() { // plan already finished
if p.LastFinishedRun != nil && !p.LastFinishedRun.IsZero() { // plan already finished
t := p.LastFinishedRun.Format(timeLayout)
msg = fmt.Sprintf("last finished run at %s (%s)", t, string(p.Status))
} else if p.Status.IsRunning() {
Expand Down

0 comments on commit 8df525a

Please sign in to comment.