Skip to content

Commit

Permalink
fix(lifecycle-operator): avoid setting the overall state of an App or…
Browse files Browse the repository at this point in the history
… WorkloadInstance between state transitions (#1871)

Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
  • Loading branch information
bacherfl committed Aug 16, 2023
1 parent 4407fc4 commit ee0b085
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lifecycle-operator/controllers/common/phasehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func (r PhaseHandler) handleCompletedPhase(state apicommon.KeptnState, piWrapper
return &PhaseResult{Continue: false, Result: ctrl.Result{}}, nil
}

piWrapper.SetState(apicommon.StateSucceeded)
// end the current phase do not set the overall state of the whole object to Succeeded here, as this can cause
// premature progression of reconcile objects that depend on the completion of another
spanPhaseTrace.AddEvent(phase.LongName + " has succeeded")
spanPhaseTrace.SetStatus(codes.Ok, "Succeeded")
spanPhaseTrace.End()
Expand Down
2 changes: 1 addition & 1 deletion lifecycle-operator/controllers/common/phasehandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestPhaseHandler(t *testing.T) {
wantErr: nil,
wantObject: &v1alpha3.KeptnAppVersion{
Status: v1alpha3.KeptnAppVersionStatus{
Status: apicommon.StateSucceeded,
Status: apicommon.StatePending,
CurrentPhase: apicommon.PhaseAppDeployment.ShortName,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,21 @@ func (r *KeptnAppVersionReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}
}

err = r.Client.Status().Update(ctx, appVersion)
if err != nil {
span.SetStatus(codes.Error, err.Error())
return ctrl.Result{Requeue: true}, err
}
// AppVersion is completed at this place

return r.finishKeptnAppVersionReconcile(ctx, appVersion, spanAppTrace)
return r.finishKeptnAppVersionReconcile(ctx, appVersion, spanAppTrace, span)
}

func (r *KeptnAppVersionReconciler) finishKeptnAppVersionReconcile(ctx context.Context, appVersion *klcv1alpha3.KeptnAppVersion, spanAppTrace trace.Span) (ctrl.Result, error) {
func (r *KeptnAppVersionReconciler) finishKeptnAppVersionReconcile(ctx context.Context, appVersion *klcv1alpha3.KeptnAppVersion, spanAppTrace, span trace.Span) (ctrl.Result, error) {

if !appVersion.IsEndTimeSet() {
appVersion.Status.CurrentPhase = apicommon.PhaseCompleted.ShortName
appVersion.Status.Status = apicommon.StateSucceeded
appVersion.SetEndTime()
}

err := r.Client.Status().Update(ctx, appVersion)
if err != nil {
span.SetStatus(codes.Error, err.Error())
return ctrl.Result{Requeue: true}, err
}

Expand Down

0 comments on commit ee0b085

Please sign in to comment.