diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go index 966fac5a63..8fe8127414 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go @@ -56,6 +56,7 @@ type KeptnAppVersionReconciler struct { Meters apicommon.KeptnMeters SpanHandler telemetry.ISpanHandler EvaluationHandler evaluation.IEvaluationHandler + PhaseHandler phase.IHandler } // +kubebuilder:rbac:groups=lifecycle.keptn.sh,resources=keptnappversions,verbs=get;list;watch;create;update;patch;delete @@ -92,12 +93,6 @@ func (r *KeptnAppVersionReconciler) Reconcile(ctx context.Context, req ctrl.Requ defer completionFunc() currentPhase := apicommon.PhaseAppPreDeployment - phaseHandler := phase.Handler{ - Client: r.Client, - EventSender: r.EventSender, - Log: r.Log, - SpanHandler: r.SpanHandler, - } ctxAppTrace, spanAppTrace, err := r.SpanHandler.GetSpan(ctxAppTrace, r.getTracer(), appVersion, "") if err != nil { @@ -113,7 +108,7 @@ func (r *KeptnAppVersionReconciler) Reconcile(ctx context.Context, req ctrl.Requ reconcilePreDep := func(phaseCtx context.Context) (apicommon.KeptnState, error) { return r.reconcilePrePostDeployment(ctx, phaseCtx, appVersion, apicommon.PreDeploymentCheckType) } - result, err := phaseHandler.HandlePhase(ctx, ctxAppTrace, r.getTracer(), appVersion, currentPhase, reconcilePreDep) + result, err := r.PhaseHandler.HandlePhase(ctx, ctxAppTrace, r.getTracer(), appVersion, currentPhase, reconcilePreDep) if !result.Continue { return result.Result, err } @@ -124,7 +119,7 @@ func (r *KeptnAppVersionReconciler) Reconcile(ctx context.Context, req ctrl.Requ reconcilePreEval := func(phaseCtx context.Context) (apicommon.KeptnState, error) { return r.reconcilePrePostEvaluation(ctx, phaseCtx, appVersion, apicommon.PreDeploymentEvaluationCheckType) } - result, err := phaseHandler.HandlePhase(ctx, ctxAppTrace, r.getTracer(), appVersion, currentPhase, reconcilePreEval) + result, err := r.PhaseHandler.HandlePhase(ctx, ctxAppTrace, r.getTracer(), appVersion, currentPhase, reconcilePreEval) if !result.Continue { return result.Result, err } @@ -135,7 +130,7 @@ func (r *KeptnAppVersionReconciler) Reconcile(ctx context.Context, req ctrl.Requ reconcileAppDep := func(phaseCtx context.Context) (apicommon.KeptnState, error) { return r.reconcileWorkloads(ctx, appVersion) } - result, err := phaseHandler.HandlePhase(ctx, ctxAppTrace, r.getTracer(), appVersion, currentPhase, reconcileAppDep) + result, err := r.PhaseHandler.HandlePhase(ctx, ctxAppTrace, r.getTracer(), appVersion, currentPhase, reconcileAppDep) if !result.Continue { return result.Result, err } @@ -146,7 +141,7 @@ func (r *KeptnAppVersionReconciler) Reconcile(ctx context.Context, req ctrl.Requ reconcilePostDep := func(phaseCtx context.Context) (apicommon.KeptnState, error) { return r.reconcilePrePostDeployment(ctx, phaseCtx, appVersion, apicommon.PostDeploymentCheckType) } - result, err := phaseHandler.HandlePhase(ctx, ctxAppTrace, r.getTracer(), appVersion, currentPhase, reconcilePostDep) + result, err := r.PhaseHandler.HandlePhase(ctx, ctxAppTrace, r.getTracer(), appVersion, currentPhase, reconcilePostDep) if !result.Continue { return result.Result, err } @@ -157,7 +152,7 @@ func (r *KeptnAppVersionReconciler) Reconcile(ctx context.Context, req ctrl.Requ reconcilePostEval := func(phaseCtx context.Context) (apicommon.KeptnState, error) { return r.reconcilePrePostEvaluation(ctx, phaseCtx, appVersion, apicommon.PostDeploymentEvaluationCheckType) } - result, err := phaseHandler.HandlePhase(ctx, ctxAppTrace, r.getTracer(), appVersion, currentPhase, reconcilePostEval) + result, err := r.PhaseHandler.HandlePhase(ctx, ctxAppTrace, r.getTracer(), appVersion, currentPhase, reconcilePostEval) if !result.Continue { return result.Result, err } diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go index cbd5528546..6a92abf3eb 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go @@ -3,6 +3,8 @@ package keptnappversion import ( "context" "fmt" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/phase" + phasefake "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/phase/fake" "reflect" "strings" "testing" @@ -50,6 +52,10 @@ func TestKeptnAppVersionReconciler_reconcile(t *testing.T) { r, eventChannel, _ := setupReconciler(app) + r.PhaseHandler = &phasefake.MockHandler{HandlePhaseFunc: func(ctx context.Context, ctxTrace context.Context, tracer trace.Tracer, reconcileObject client.Object, phaseMoqParam apicommon.KeptnPhaseType, reconcilePhase func(phaseCtx context.Context) (apicommon.KeptnState, error)) (phase.PhaseResult, error) { + return phase.PhaseResult{Continue: true, Result: ctrl.Result{Requeue: false}}, nil + }} + tests := []struct { name string req ctrl.Request @@ -66,16 +72,7 @@ func TestKeptnAppVersionReconciler_reconcile(t *testing.T) { }, wantErr: nil, events: []string{ - `AppPreDeployTasksStarted`, - `AppPreDeployTasksFinished`, - `AppPreDeployEvaluationsStarted`, - `AppPreDeployEvaluationsFinished`, - `AppDeployStarted`, - `AppDeployFinished`, - `AppPostDeployTasksStarted`, - `AppPostDeployTasksFinished`, - `AppPostDeployEvaluationsStarted`, - `AppPostDeployEvaluationsFinished`, + `AppCompletedFinished`, }, }, { diff --git a/lifecycle-operator/main.go b/lifecycle-operator/main.go index 7f193aa994..0deac281ba 100644 --- a/lifecycle-operator/main.go +++ b/lifecycle-operator/main.go @@ -318,6 +318,12 @@ func main() { mgr.GetScheme(), spanHandler, ) + appVersionPhaseHandler := phase.NewHandler( + mgr.GetClient(), + appVersionEventSender, + appVersionLogger, + spanHandler, + ) appVersionReconciler := &keptnappversion.KeptnAppVersionReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), @@ -327,6 +333,7 @@ func main() { Meters: keptnMeters, SpanHandler: spanHandler, EvaluationHandler: appVersionEvaluationHandler, + PhaseHandler: appVersionPhaseHandler, } if err = (appVersionReconciler).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KeptnAppVersion")