Skip to content

Commit

Permalink
chore(lifecycle-operator): adapt KeptnAppVersionReconciler to make us…
Browse files Browse the repository at this point in the history
…e of PhaseHandler interface

Signed-off-by: Florian Bacher <[email protected]>
  • Loading branch information
bacherfl committed Nov 9, 2023
1 parent 8341dbf commit 80bac59
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package keptnappversion
import (
"context"
"fmt"
"github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/phase"

Check failure on line 6 in lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint (lifecycle-operator, lifecycle-operator/)

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
phasefake "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/phase/fake"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -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
Expand All @@ -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`,
},
},
{
Expand Down
7 changes: 7 additions & 0 deletions lifecycle-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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")
Expand Down

0 comments on commit 80bac59

Please sign in to comment.