Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lifecycle-operator): avoid setting the overall state of an App or WorkloadInstance between state transitions #1871

Merged
merged 6 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,
bacherfl marked this conversation as resolved.
Show resolved Hide resolved
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