From 29e244f93d8258e8abfc7a788f37587f33950a84 Mon Sep 17 00:00:00 2001 From: RealAnna Date: Tue, 19 Mar 2024 10:08:21 +0100 Subject: [PATCH 1/7] chore: remove noops tracer for evaluations Signed-off-by: RealAnna --- .../controllers/common/evaluation/handler.go | 18 +++++++++--------- .../reconcile_prepostevaluation.go | 2 +- .../reconcile_prepostevaluation.go | 2 +- lifecycle-operator/main.go | 3 --- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lifecycle-operator/controllers/common/evaluation/handler.go b/lifecycle-operator/controllers/common/evaluation/handler.go index 05562a8445..586120d5bc 100644 --- a/lifecycle-operator/controllers/common/evaluation/handler.go +++ b/lifecycle-operator/controllers/common/evaluation/handler.go @@ -24,14 +24,13 @@ import ( //go:generate moq -pkg fake -skip-ensure -out ./fake/evaluationhandler_mock.go . IEvaluationHandler:MockEvaluationHandler type IEvaluationHandler interface { - ReconcileEvaluations(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) + ReconcileEvaluations(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) } type Handler struct { client.Client EventSender eventsender.IEvent Log logr.Logger - Tracer telemetry.ITracer Scheme *runtime.Scheme SpanHandler telemetry.ISpanHandler } @@ -43,19 +42,18 @@ type CreateEvaluationAttributes struct { } // NewHandler creates a new instance of the Handler. -func NewHandler(client client.Client, eventSender eventsender.IEvent, log logr.Logger, tracer telemetry.ITracer, scheme *runtime.Scheme, spanHandler telemetry.ISpanHandler) Handler { +func NewHandler(client client.Client, eventSender eventsender.IEvent, log logr.Logger, scheme *runtime.Scheme, spanHandler telemetry.ISpanHandler) Handler { return Handler{ Client: client, EventSender: eventSender, Log: log, - Tracer: tracer, Scheme: scheme, SpanHandler: spanHandler, } } //nolint:gocognit,gocyclo -func (r Handler) ReconcileEvaluations(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { +func (r Handler) ReconcileEvaluations(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { piWrapper, err := interfaces.NewPhaseItemWrapperFromClientObject(reconcileObject) if err != nil { return nil, apicommon.StatusSummary{}, err @@ -100,6 +98,7 @@ func (r Handler) ReconcileEvaluations(ctx context.Context, phaseCtx context.Cont err := r.handleEvaluationNotExists( ctx, phaseCtx, + tracer, evaluationCreateAttributes, evaluationName, piWrapper, @@ -128,6 +127,7 @@ func (r Handler) ReconcileEvaluations(ctx context.Context, phaseCtx context.Cont r.handleEvaluationExists( phaseCtx, piWrapper, + tracer, evaluation, &evaluationStatus, ) @@ -194,7 +194,7 @@ func (r Handler) setupEvaluations(evaluationCreateAttributes CreateEvaluationAtt return evaluations, statuses } -func (r Handler) handleEvaluationNotExists(ctx context.Context, phaseCtx context.Context, evaluationCreateAttributes CreateEvaluationAttributes, evaluationName string, piWrapper *interfaces.PhaseItemWrapper, reconcileObject client.Object, evaluation *klcv1beta1.KeptnEvaluation, evaluationStatus *klcv1beta1.ItemStatus) error { +func (r Handler) handleEvaluationNotExists(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, evaluationCreateAttributes CreateEvaluationAttributes, evaluationName string, piWrapper *interfaces.PhaseItemWrapper, reconcileObject client.Object, evaluation *klcv1beta1.KeptnEvaluation, evaluationStatus *klcv1beta1.ItemStatus) error { definition, err := common.GetEvaluationDefinition(r.Client, r.Log, ctx, evaluationName, piWrapper.GetNamespace()) if err != nil { return controllererrors.ErrCannotGetKeptnEvaluationDefinition @@ -206,7 +206,7 @@ func (r Handler) handleEvaluationNotExists(ctx context.Context, phaseCtx context } evaluationStatus.Name = evaluationName evaluationStatus.SetStartTime() - _, _, err = r.SpanHandler.GetSpan(phaseCtx, r.Tracer, evaluation, "") + _, _, err = r.SpanHandler.GetSpan(phaseCtx, tracer, evaluation, "") if err != nil { r.Log.Error(err, "could not get span") } @@ -214,8 +214,8 @@ func (r Handler) handleEvaluationNotExists(ctx context.Context, phaseCtx context return nil } -func (r Handler) handleEvaluationExists(phaseCtx context.Context, piWrapper *interfaces.PhaseItemWrapper, evaluation *klcv1beta1.KeptnEvaluation, evaluationStatus *klcv1beta1.ItemStatus) { - _, spanEvaluationTrace, err := r.SpanHandler.GetSpan(phaseCtx, r.Tracer, evaluation, "") +func (r Handler) handleEvaluationExists(phaseCtx context.Context, piWrapper *interfaces.PhaseItemWrapper, tracer telemetry.ITracer, evaluation *klcv1beta1.KeptnEvaluation, evaluationStatus *klcv1beta1.ItemStatus) { + _, spanEvaluationTrace, err := r.SpanHandler.GetSpan(phaseCtx, tracer, evaluation, "") if err != nil { r.Log.Error(err, "could not get span") } diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_prepostevaluation.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_prepostevaluation.go index a66b707784..75f28d9096 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_prepostevaluation.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_prepostevaluation.go @@ -16,7 +16,7 @@ func (r *KeptnAppVersionReconciler) reconcilePrePostEvaluation(ctx context.Conte CheckType: checkType, } - newStatus, state, err := r.EvaluationHandler.ReconcileEvaluations(ctx, phaseCtx, appVersion, evaluationCreateAttributes) + newStatus, state, err := r.EvaluationHandler.ReconcileEvaluations(ctx, phaseCtx, r.getTracer(), appVersion, evaluationCreateAttributes) if err != nil { return apicommon.StateUnknown, err } diff --git a/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/reconcile_prepostevaluation.go b/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/reconcile_prepostevaluation.go index 5694ebee1e..e6274f1d10 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/reconcile_prepostevaluation.go +++ b/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/reconcile_prepostevaluation.go @@ -16,7 +16,7 @@ func (r *KeptnWorkloadVersionReconciler) reconcilePrePostEvaluation(ctx context. CheckType: checkType, } - newStatus, state, err := r.EvaluationHandler.ReconcileEvaluations(ctx, phaseCtx, workloadVersion, evaluationCreateAttributes) + newStatus, state, err := r.EvaluationHandler.ReconcileEvaluations(ctx, phaseCtx, r.getTracer(), workloadVersion, evaluationCreateAttributes) if err != nil { return apicommon.StateUnknown, err } diff --git a/lifecycle-operator/main.go b/lifecycle-operator/main.go index c04be36378..eb8e598d37 100644 --- a/lifecycle-operator/main.go +++ b/lifecycle-operator/main.go @@ -56,7 +56,6 @@ import ( otelprom "go.opentelemetry.io/otel/exporters/prometheus" metricsapi "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/sdk/metric" - "go.opentelemetry.io/otel/trace/noop" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" @@ -283,7 +282,6 @@ func main() { mgr.GetClient(), workloadVersionEventSender, workloadVersionLogger, - noop.NewTracerProvider().Tracer("keptn/lifecycle-operator/workloadversion"), mgr.GetScheme(), spanHandler, ) @@ -317,7 +315,6 @@ func main() { mgr.GetClient(), appVersionEventSender, appVersionLogger, - noop.NewTracerProvider().Tracer("keptn/lifecycle-operator/appversion"), mgr.GetScheme(), spanHandler, ) From a2e329c168e99dd79dcb341f6580c2c5ced35392 Mon Sep 17 00:00:00 2001 From: RealAnna Date: Tue, 19 Mar 2024 10:17:36 +0100 Subject: [PATCH 2/7] fix: eval handler mock Signed-off-by: RealAnna --- .../evaluation/fake/evaluationhandler_mock.go | 15 +++++++++++---- .../controllers/common/evaluation/handler_test.go | 4 +--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lifecycle-operator/controllers/common/evaluation/fake/evaluationhandler_mock.go b/lifecycle-operator/controllers/common/evaluation/fake/evaluationhandler_mock.go index 8626fcf202..45445e4c9b 100644 --- a/lifecycle-operator/controllers/common/evaluation/fake/evaluationhandler_mock.go +++ b/lifecycle-operator/controllers/common/evaluation/fake/evaluationhandler_mock.go @@ -8,6 +8,7 @@ import ( klcv1beta1 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1beta1" apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1beta1/common" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/evaluation" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "sigs.k8s.io/controller-runtime/pkg/client" "sync" ) @@ -18,7 +19,7 @@ import ( // // // make and configure a mocked evaluation.IEvaluationHandler // mockedIEvaluationHandler := &MockEvaluationHandler{ -// ReconcileEvaluationsFunc: func(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { +// ReconcileEvaluationsFunc: func(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { // panic("mock out the ReconcileEvaluations method") // }, // } @@ -29,7 +30,7 @@ import ( // } type MockEvaluationHandler struct { // ReconcileEvaluationsFunc mocks the ReconcileEvaluations method. - ReconcileEvaluationsFunc func(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) + ReconcileEvaluationsFunc func(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) // calls tracks calls to the methods. calls struct { @@ -39,6 +40,8 @@ type MockEvaluationHandler struct { Ctx context.Context // PhaseCtx is the phaseCtx argument value. PhaseCtx context.Context + // Tracer is the tracer argument value. + Tracer telemetry.ITracer // ReconcileObject is the reconcileObject argument value. ReconcileObject client.Object // EvaluationCreateAttributes is the evaluationCreateAttributes argument value. @@ -49,25 +52,27 @@ type MockEvaluationHandler struct { } // ReconcileEvaluations calls ReconcileEvaluationsFunc. -func (mock *MockEvaluationHandler) ReconcileEvaluations(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { +func (mock *MockEvaluationHandler) ReconcileEvaluations(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { if mock.ReconcileEvaluationsFunc == nil { panic("MockEvaluationHandler.ReconcileEvaluationsFunc: method is nil but IEvaluationHandler.ReconcileEvaluations was just called") } callInfo := struct { Ctx context.Context PhaseCtx context.Context + Tracer telemetry.ITracer ReconcileObject client.Object EvaluationCreateAttributes evaluation.CreateEvaluationAttributes }{ Ctx: ctx, PhaseCtx: phaseCtx, + Tracer: tracer, ReconcileObject: reconcileObject, EvaluationCreateAttributes: evaluationCreateAttributes, } mock.lockReconcileEvaluations.Lock() mock.calls.ReconcileEvaluations = append(mock.calls.ReconcileEvaluations, callInfo) mock.lockReconcileEvaluations.Unlock() - return mock.ReconcileEvaluationsFunc(ctx, phaseCtx, reconcileObject, evaluationCreateAttributes) + return mock.ReconcileEvaluationsFunc(ctx, phaseCtx, tracer, reconcileObject, evaluationCreateAttributes) } // ReconcileEvaluationsCalls gets all the calls that were made to ReconcileEvaluations. @@ -77,12 +82,14 @@ func (mock *MockEvaluationHandler) ReconcileEvaluations(ctx context.Context, pha func (mock *MockEvaluationHandler) ReconcileEvaluationsCalls() []struct { Ctx context.Context PhaseCtx context.Context + Tracer telemetry.ITracer ReconcileObject client.Object EvaluationCreateAttributes evaluation.CreateEvaluationAttributes } { var calls []struct { Ctx context.Context PhaseCtx context.Context + Tracer telemetry.ITracer ReconcileObject client.Object EvaluationCreateAttributes evaluation.CreateEvaluationAttributes } diff --git a/lifecycle-operator/controllers/common/evaluation/handler_test.go b/lifecycle-operator/controllers/common/evaluation/handler_test.go index 19c341df07..7ac1c1d451 100644 --- a/lifecycle-operator/controllers/common/evaluation/handler_test.go +++ b/lifecycle-operator/controllers/common/evaluation/handler_test.go @@ -412,10 +412,9 @@ func TestEvaluationHandler(t *testing.T) { fake.NewClientBuilder().WithObjects(initObjs...).Build(), eventsender.NewK8sSender(fakeRecorder), ctrl.Log.WithName("controller"), - noop.NewTracerProvider().Tracer("tracer"), scheme.Scheme, &spanHandlerMock) - status, summary, err := handler.ReconcileEvaluations(context.TODO(), context.TODO(), tt.object, tt.createAttr) + status, summary, err := handler.ReconcileEvaluations(context.TODO(), context.TODO(), noop.NewTracerProvider().Tracer("tracer"), tt.object, tt.createAttr) if len(tt.wantStatus) == len(status) { for j, item := range status { require.Equal(t, tt.wantStatus[j].DefinitionName, item.DefinitionName) @@ -495,7 +494,6 @@ func TestEvaluationHandler_createEvaluation(t *testing.T) { fake.NewClientBuilder().Build(), eventsender.NewK8sSender(record.NewFakeRecorder(100)), ctrl.Log.WithName("controller"), - noop.NewTracerProvider().Tracer("tracer"), scheme.Scheme, &telemetryfake.ISpanHandlerMock{}) From edf5963996f1f6e823a3194c3dffdf8cfe11c12e Mon Sep 17 00:00:00 2001 From: RealAnna Date: Tue, 19 Mar 2024 10:20:28 +0100 Subject: [PATCH 3/7] fix: add tracer telemetry.ITracer, Signed-off-by: RealAnna --- .../controllers/lifecycle/keptnappversion/controller_test.go | 2 +- .../lifecycle/keptnworkloadversion/controller_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go index ae0c3ef2d3..90479389f9 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go @@ -508,7 +508,7 @@ func setupReconciler(objs ...client.Object) (*KeptnAppVersionReconciler, chan st Meters: testcommon.InitAppMeters(), Config: config.Instance(), EvaluationHandler: &evalfake.MockEvaluationHandler{ - ReconcileEvaluationsFunc: func(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]lfcv1beta1.ItemStatus, apicommon.StatusSummary, error) { + ReconcileEvaluationsFunc: func(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]lfcv1beta1.ItemStatus, apicommon.StatusSummary, error) { return []lfcv1beta1.ItemStatus{}, apicommon.StatusSummary{}, nil }, }, diff --git a/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller_test.go b/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller_test.go index 9aa76f10e1..dc78b05dfb 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller_test.go +++ b/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller_test.go @@ -1019,7 +1019,7 @@ func TestKeptnWorkloadVersionReconciler_ReconcilePreDeploymentEvaluationUnexpect mockEvaluationHandler := r.EvaluationHandler.(*evaluationfake.MockEvaluationHandler) - mockEvaluationHandler.ReconcileEvaluationsFunc = func(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { + mockEvaluationHandler.ReconcileEvaluationsFunc = func(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { return nil, apicommon.StatusSummary{}, errors.New("unexpected error") } @@ -1084,7 +1084,7 @@ func setupReconciler(objs ...client.Object) (*KeptnWorkloadVersionReconciler, ch TracerFactory: tf, Config: config.Instance(), EvaluationHandler: &evaluationfake.MockEvaluationHandler{ - ReconcileEvaluationsFunc: func(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { + ReconcileEvaluationsFunc: func(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { return []klcv1beta1.ItemStatus{}, apicommon.StatusSummary{}, nil }, }, From 7045c2a403b43d5fe3ae9a514c7eba74c23fe3d5 Mon Sep 17 00:00:00 2001 From: RealAnna Date: Tue, 19 Mar 2024 10:22:44 +0100 Subject: [PATCH 4/7] fix: remove tracer from suite tests Signed-off-by: RealAnna --- .../test/component/appversion/appversion_suite_test.go | 1 - .../test/component/workloadversion/workloadversion_suite_test.go | 1 - 2 files changed, 2 deletions(-) diff --git a/lifecycle-operator/test/component/appversion/appversion_suite_test.go b/lifecycle-operator/test/component/appversion/appversion_suite_test.go index 3d2a8973be..a93f21af1f 100644 --- a/lifecycle-operator/test/component/appversion/appversion_suite_test.go +++ b/lifecycle-operator/test/component/appversion/appversion_suite_test.go @@ -48,7 +48,6 @@ var _ = BeforeSuite(func() { k8sManager.GetClient(), eventsender.NewK8sSender(k8sManager.GetEventRecorderFor("test-appversion-controller")), GinkgoLogr, - tracerFactory.GetTracer(traceComponentName), k8sManager.GetScheme(), &telemetry.Handler{}) diff --git a/lifecycle-operator/test/component/workloadversion/workloadversion_suite_test.go b/lifecycle-operator/test/component/workloadversion/workloadversion_suite_test.go index 5bedc38c0b..6fc47b851b 100644 --- a/lifecycle-operator/test/component/workloadversion/workloadversion_suite_test.go +++ b/lifecycle-operator/test/component/workloadversion/workloadversion_suite_test.go @@ -50,7 +50,6 @@ var _ = BeforeSuite(func() { k8sManager.GetClient(), eventSender, GinkgoLogr, - tracerFactory.GetTracer(traceComponentName), k8sManager.GetScheme(), &telemetry.Handler{}) From ca74fc160bc3f48482be8800172af2bfbedaa4e9 Mon Sep 17 00:00:00 2001 From: RealAnna Date: Tue, 19 Mar 2024 11:36:09 +0100 Subject: [PATCH 5/7] fix: init evaluation handler as for task handler Signed-off-by: RealAnna --- .../controllers/common/evaluation/handler.go | 16 ++++---- .../common/evaluation/handler_test.go | 4 +- .../reconcile_prepostevaluation.go | 10 ++++- .../reconcile_prepostevaluation.go | 11 +++++- lifecycle-operator/main.go | 37 ++++++------------- 5 files changed, 41 insertions(+), 37 deletions(-) diff --git a/lifecycle-operator/controllers/common/evaluation/handler.go b/lifecycle-operator/controllers/common/evaluation/handler.go index 586120d5bc..1524f05ac1 100644 --- a/lifecycle-operator/controllers/common/evaluation/handler.go +++ b/lifecycle-operator/controllers/common/evaluation/handler.go @@ -31,6 +31,7 @@ type Handler struct { client.Client EventSender eventsender.IEvent Log logr.Logger + Tracer telemetry.ITracer Scheme *runtime.Scheme SpanHandler telemetry.ISpanHandler } @@ -42,18 +43,19 @@ type CreateEvaluationAttributes struct { } // NewHandler creates a new instance of the Handler. -func NewHandler(client client.Client, eventSender eventsender.IEvent, log logr.Logger, scheme *runtime.Scheme, spanHandler telemetry.ISpanHandler) Handler { +func NewHandler(client client.Client, eventSender eventsender.IEvent, tracer telemetry.ITracer, log logr.Logger, scheme *runtime.Scheme, spanHandler telemetry.ISpanHandler) Handler { return Handler{ Client: client, EventSender: eventSender, Log: log, + Tracer: tracer, Scheme: scheme, SpanHandler: spanHandler, } } //nolint:gocognit,gocyclo -func (r Handler) ReconcileEvaluations(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { +func (r Handler) ReconcileEvaluations(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { piWrapper, err := interfaces.NewPhaseItemWrapperFromClientObject(reconcileObject) if err != nil { return nil, apicommon.StatusSummary{}, err @@ -98,7 +100,6 @@ func (r Handler) ReconcileEvaluations(ctx context.Context, phaseCtx context.Cont err := r.handleEvaluationNotExists( ctx, phaseCtx, - tracer, evaluationCreateAttributes, evaluationName, piWrapper, @@ -127,7 +128,6 @@ func (r Handler) ReconcileEvaluations(ctx context.Context, phaseCtx context.Cont r.handleEvaluationExists( phaseCtx, piWrapper, - tracer, evaluation, &evaluationStatus, ) @@ -194,7 +194,7 @@ func (r Handler) setupEvaluations(evaluationCreateAttributes CreateEvaluationAtt return evaluations, statuses } -func (r Handler) handleEvaluationNotExists(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, evaluationCreateAttributes CreateEvaluationAttributes, evaluationName string, piWrapper *interfaces.PhaseItemWrapper, reconcileObject client.Object, evaluation *klcv1beta1.KeptnEvaluation, evaluationStatus *klcv1beta1.ItemStatus) error { +func (r Handler) handleEvaluationNotExists(ctx context.Context, phaseCtx context.Context, evaluationCreateAttributes CreateEvaluationAttributes, evaluationName string, piWrapper *interfaces.PhaseItemWrapper, reconcileObject client.Object, evaluation *klcv1beta1.KeptnEvaluation, evaluationStatus *klcv1beta1.ItemStatus) error { definition, err := common.GetEvaluationDefinition(r.Client, r.Log, ctx, evaluationName, piWrapper.GetNamespace()) if err != nil { return controllererrors.ErrCannotGetKeptnEvaluationDefinition @@ -206,7 +206,7 @@ func (r Handler) handleEvaluationNotExists(ctx context.Context, phaseCtx context } evaluationStatus.Name = evaluationName evaluationStatus.SetStartTime() - _, _, err = r.SpanHandler.GetSpan(phaseCtx, tracer, evaluation, "") + _, _, err = r.SpanHandler.GetSpan(phaseCtx, r.Tracer, evaluation, "") if err != nil { r.Log.Error(err, "could not get span") } @@ -214,8 +214,8 @@ func (r Handler) handleEvaluationNotExists(ctx context.Context, phaseCtx context return nil } -func (r Handler) handleEvaluationExists(phaseCtx context.Context, piWrapper *interfaces.PhaseItemWrapper, tracer telemetry.ITracer, evaluation *klcv1beta1.KeptnEvaluation, evaluationStatus *klcv1beta1.ItemStatus) { - _, spanEvaluationTrace, err := r.SpanHandler.GetSpan(phaseCtx, tracer, evaluation, "") +func (r Handler) handleEvaluationExists(phaseCtx context.Context, piWrapper *interfaces.PhaseItemWrapper, evaluation *klcv1beta1.KeptnEvaluation, evaluationStatus *klcv1beta1.ItemStatus) { + _, spanEvaluationTrace, err := r.SpanHandler.GetSpan(phaseCtx, r.Tracer, evaluation, "") if err != nil { r.Log.Error(err, "could not get span") } diff --git a/lifecycle-operator/controllers/common/evaluation/handler_test.go b/lifecycle-operator/controllers/common/evaluation/handler_test.go index 7ac1c1d451..3adb7e15b7 100644 --- a/lifecycle-operator/controllers/common/evaluation/handler_test.go +++ b/lifecycle-operator/controllers/common/evaluation/handler_test.go @@ -411,10 +411,11 @@ func TestEvaluationHandler(t *testing.T) { handler := NewHandler( fake.NewClientBuilder().WithObjects(initObjs...).Build(), eventsender.NewK8sSender(fakeRecorder), + noop.NewTracerProvider().Tracer("tracer"), ctrl.Log.WithName("controller"), scheme.Scheme, &spanHandlerMock) - status, summary, err := handler.ReconcileEvaluations(context.TODO(), context.TODO(), noop.NewTracerProvider().Tracer("tracer"), tt.object, tt.createAttr) + status, summary, err := handler.ReconcileEvaluations(context.TODO(), context.TODO(), tt.object, tt.createAttr) if len(tt.wantStatus) == len(status) { for j, item := range status { require.Equal(t, tt.wantStatus[j].DefinitionName, item.DefinitionName) @@ -493,6 +494,7 @@ func TestEvaluationHandler_createEvaluation(t *testing.T) { handler := NewHandler( fake.NewClientBuilder().Build(), eventsender.NewK8sSender(record.NewFakeRecorder(100)), + noop.NewTracerProvider().Tracer("tracer"), ctrl.Log.WithName("controller"), scheme.Scheme, &telemetryfake.ISpanHandlerMock{}) diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_prepostevaluation.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_prepostevaluation.go index 75f28d9096..7ed123d888 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_prepostevaluation.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_prepostevaluation.go @@ -15,8 +15,16 @@ func (r *KeptnAppVersionReconciler) reconcilePrePostEvaluation(ctx context.Conte SpanName: fmt.Sprintf(apicommon.CreateAppEvalSpanName, checkType), CheckType: checkType, } + evaluationHandler := evaluation.NewHandler( + r.Client, + r.EventSender, + r.getTracer(), + r.Log, + r.Client.Scheme(), + r.SpanHandler, + ) - newStatus, state, err := r.EvaluationHandler.ReconcileEvaluations(ctx, phaseCtx, r.getTracer(), appVersion, evaluationCreateAttributes) + newStatus, state, err := evaluationHandler.ReconcileEvaluations(ctx, phaseCtx, appVersion, evaluationCreateAttributes) if err != nil { return apicommon.StateUnknown, err } diff --git a/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/reconcile_prepostevaluation.go b/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/reconcile_prepostevaluation.go index e6274f1d10..2601d4c899 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/reconcile_prepostevaluation.go +++ b/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/reconcile_prepostevaluation.go @@ -16,7 +16,16 @@ func (r *KeptnWorkloadVersionReconciler) reconcilePrePostEvaluation(ctx context. CheckType: checkType, } - newStatus, state, err := r.EvaluationHandler.ReconcileEvaluations(ctx, phaseCtx, r.getTracer(), workloadVersion, evaluationCreateAttributes) + evaluationHandler := evaluation.NewHandler( + r.Client, + r.EventSender, + r.getTracer(), + r.Log, + r.Client.Scheme(), + r.SpanHandler, + ) + + newStatus, state, err := evaluationHandler.ReconcileEvaluations(ctx, phaseCtx, workloadVersion, evaluationCreateAttributes) if err != nil { return apicommon.StateUnknown, err } diff --git a/lifecycle-operator/main.go b/lifecycle-operator/main.go index eb8e598d37..8d0d58f94a 100644 --- a/lifecycle-operator/main.go +++ b/lifecycle-operator/main.go @@ -37,7 +37,6 @@ import ( lifecyclev1beta1 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1beta1" optionsv1alpha1 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/options/v1alpha1" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/config" - "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/evaluation" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/eventsender" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/phase" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" @@ -278,13 +277,7 @@ func main() { workloadVersionLogger := ctrl.Log.WithName("KeptnWorkloadVersion Controller").V(env.KeptnWorkloadVersionControllerLogLevel) workloadVersionRecorder := mgr.GetEventRecorderFor("keptnworkloadversion-controller") workloadVersionEventSender := eventsender.NewEventMultiplexer(workloadVersionLogger, workloadVersionRecorder, ceClient) - workloadVersionEvaluationHandler := evaluation.NewHandler( - mgr.GetClient(), - workloadVersionEventSender, - workloadVersionLogger, - mgr.GetScheme(), - spanHandler, - ) + workloadVersionPhaseHandler := phase.NewHandler( mgr.GetClient(), workloadVersionEventSender, @@ -292,16 +285,15 @@ func main() { spanHandler, ) workloadVersionReconciler := &keptnworkloadversion.KeptnWorkloadVersionReconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), - Log: workloadVersionLogger, - EventSender: workloadVersionEventSender, - Meters: keptnMeters, - TracerFactory: telemetry.GetOtelInstance(), - SpanHandler: spanHandler, - EvaluationHandler: workloadVersionEvaluationHandler, - PhaseHandler: workloadVersionPhaseHandler, - Config: config.Instance(), + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + Log: workloadVersionLogger, + EventSender: workloadVersionEventSender, + Meters: keptnMeters, + TracerFactory: telemetry.GetOtelInstance(), + SpanHandler: spanHandler, + PhaseHandler: workloadVersionPhaseHandler, + Config: config.Instance(), } if err = (workloadVersionReconciler).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KeptnWorkloadVersion") @@ -311,13 +303,7 @@ func main() { appVersionLogger := ctrl.Log.WithName("KeptnAppVersion Controller").V(env.KeptnAppVersionControllerLogLevel) appVersionRecorder := mgr.GetEventRecorderFor("keptnappversion-controller") appVersionEventSender := eventsender.NewEventMultiplexer(appVersionLogger, appVersionRecorder, ceClient) - appVersionEvaluationHandler := evaluation.NewHandler( - mgr.GetClient(), - appVersionEventSender, - appVersionLogger, - mgr.GetScheme(), - spanHandler, - ) + appVersionPhaseHandler := phase.NewHandler( mgr.GetClient(), appVersionEventSender, @@ -332,7 +318,6 @@ func main() { TracerFactory: telemetry.GetOtelInstance(), Meters: keptnMeters, SpanHandler: spanHandler, - EvaluationHandler: appVersionEvaluationHandler, PhaseHandler: appVersionPhaseHandler, PromotionTasksEnabled: env.PromotionTasksEnabled, Config: config.Instance(), From 94e445aa8909804e463b26586bb4e2f828683555 Mon Sep 17 00:00:00 2001 From: RealAnna Date: Tue, 19 Mar 2024 11:39:45 +0100 Subject: [PATCH 6/7] fix: redo function signature Signed-off-by: RealAnna --- .../evaluation/fake/evaluationhandler_mock.go | 15 +++-------- .../controllers/common/evaluation/handler.go | 2 +- .../keptnappversion/controller_test.go | 2 +- .../keptnworkloadversion/controller_test.go | 4 +-- .../appversion/appversion_suite_test.go | 26 +++++++------------ .../workloadversion_suite_test.go | 26 +++++++------------ 6 files changed, 26 insertions(+), 49 deletions(-) diff --git a/lifecycle-operator/controllers/common/evaluation/fake/evaluationhandler_mock.go b/lifecycle-operator/controllers/common/evaluation/fake/evaluationhandler_mock.go index 45445e4c9b..8626fcf202 100644 --- a/lifecycle-operator/controllers/common/evaluation/fake/evaluationhandler_mock.go +++ b/lifecycle-operator/controllers/common/evaluation/fake/evaluationhandler_mock.go @@ -8,7 +8,6 @@ import ( klcv1beta1 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1beta1" apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1beta1/common" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/evaluation" - "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "sigs.k8s.io/controller-runtime/pkg/client" "sync" ) @@ -19,7 +18,7 @@ import ( // // // make and configure a mocked evaluation.IEvaluationHandler // mockedIEvaluationHandler := &MockEvaluationHandler{ -// ReconcileEvaluationsFunc: func(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { +// ReconcileEvaluationsFunc: func(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { // panic("mock out the ReconcileEvaluations method") // }, // } @@ -30,7 +29,7 @@ import ( // } type MockEvaluationHandler struct { // ReconcileEvaluationsFunc mocks the ReconcileEvaluations method. - ReconcileEvaluationsFunc func(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) + ReconcileEvaluationsFunc func(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) // calls tracks calls to the methods. calls struct { @@ -40,8 +39,6 @@ type MockEvaluationHandler struct { Ctx context.Context // PhaseCtx is the phaseCtx argument value. PhaseCtx context.Context - // Tracer is the tracer argument value. - Tracer telemetry.ITracer // ReconcileObject is the reconcileObject argument value. ReconcileObject client.Object // EvaluationCreateAttributes is the evaluationCreateAttributes argument value. @@ -52,27 +49,25 @@ type MockEvaluationHandler struct { } // ReconcileEvaluations calls ReconcileEvaluationsFunc. -func (mock *MockEvaluationHandler) ReconcileEvaluations(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { +func (mock *MockEvaluationHandler) ReconcileEvaluations(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { if mock.ReconcileEvaluationsFunc == nil { panic("MockEvaluationHandler.ReconcileEvaluationsFunc: method is nil but IEvaluationHandler.ReconcileEvaluations was just called") } callInfo := struct { Ctx context.Context PhaseCtx context.Context - Tracer telemetry.ITracer ReconcileObject client.Object EvaluationCreateAttributes evaluation.CreateEvaluationAttributes }{ Ctx: ctx, PhaseCtx: phaseCtx, - Tracer: tracer, ReconcileObject: reconcileObject, EvaluationCreateAttributes: evaluationCreateAttributes, } mock.lockReconcileEvaluations.Lock() mock.calls.ReconcileEvaluations = append(mock.calls.ReconcileEvaluations, callInfo) mock.lockReconcileEvaluations.Unlock() - return mock.ReconcileEvaluationsFunc(ctx, phaseCtx, tracer, reconcileObject, evaluationCreateAttributes) + return mock.ReconcileEvaluationsFunc(ctx, phaseCtx, reconcileObject, evaluationCreateAttributes) } // ReconcileEvaluationsCalls gets all the calls that were made to ReconcileEvaluations. @@ -82,14 +77,12 @@ func (mock *MockEvaluationHandler) ReconcileEvaluations(ctx context.Context, pha func (mock *MockEvaluationHandler) ReconcileEvaluationsCalls() []struct { Ctx context.Context PhaseCtx context.Context - Tracer telemetry.ITracer ReconcileObject client.Object EvaluationCreateAttributes evaluation.CreateEvaluationAttributes } { var calls []struct { Ctx context.Context PhaseCtx context.Context - Tracer telemetry.ITracer ReconcileObject client.Object EvaluationCreateAttributes evaluation.CreateEvaluationAttributes } diff --git a/lifecycle-operator/controllers/common/evaluation/handler.go b/lifecycle-operator/controllers/common/evaluation/handler.go index 1524f05ac1..dbea8f7ae0 100644 --- a/lifecycle-operator/controllers/common/evaluation/handler.go +++ b/lifecycle-operator/controllers/common/evaluation/handler.go @@ -24,7 +24,7 @@ import ( //go:generate moq -pkg fake -skip-ensure -out ./fake/evaluationhandler_mock.go . IEvaluationHandler:MockEvaluationHandler type IEvaluationHandler interface { - ReconcileEvaluations(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) + ReconcileEvaluations(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) } type Handler struct { diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go index 90479389f9..ae0c3ef2d3 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go @@ -508,7 +508,7 @@ func setupReconciler(objs ...client.Object) (*KeptnAppVersionReconciler, chan st Meters: testcommon.InitAppMeters(), Config: config.Instance(), EvaluationHandler: &evalfake.MockEvaluationHandler{ - ReconcileEvaluationsFunc: func(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]lfcv1beta1.ItemStatus, apicommon.StatusSummary, error) { + ReconcileEvaluationsFunc: func(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]lfcv1beta1.ItemStatus, apicommon.StatusSummary, error) { return []lfcv1beta1.ItemStatus{}, apicommon.StatusSummary{}, nil }, }, diff --git a/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller_test.go b/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller_test.go index dc78b05dfb..9aa76f10e1 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller_test.go +++ b/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller_test.go @@ -1019,7 +1019,7 @@ func TestKeptnWorkloadVersionReconciler_ReconcilePreDeploymentEvaluationUnexpect mockEvaluationHandler := r.EvaluationHandler.(*evaluationfake.MockEvaluationHandler) - mockEvaluationHandler.ReconcileEvaluationsFunc = func(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { + mockEvaluationHandler.ReconcileEvaluationsFunc = func(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { return nil, apicommon.StatusSummary{}, errors.New("unexpected error") } @@ -1084,7 +1084,7 @@ func setupReconciler(objs ...client.Object) (*KeptnWorkloadVersionReconciler, ch TracerFactory: tf, Config: config.Instance(), EvaluationHandler: &evaluationfake.MockEvaluationHandler{ - ReconcileEvaluationsFunc: func(ctx context.Context, phaseCtx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { + ReconcileEvaluationsFunc: func(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes evaluation.CreateEvaluationAttributes) ([]klcv1beta1.ItemStatus, apicommon.StatusSummary, error) { return []klcv1beta1.ItemStatus{}, apicommon.StatusSummary{}, nil }, }, diff --git a/lifecycle-operator/test/component/appversion/appversion_suite_test.go b/lifecycle-operator/test/component/appversion/appversion_suite_test.go index a93f21af1f..ec78ada379 100644 --- a/lifecycle-operator/test/component/appversion/appversion_suite_test.go +++ b/lifecycle-operator/test/component/appversion/appversion_suite_test.go @@ -7,7 +7,6 @@ import ( "time" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/config" - "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/evaluation" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/eventsender" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/phase" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" @@ -44,12 +43,6 @@ var _ = BeforeSuite(func() { ctx, k8sManager, tracer, spanRecorder, k8sClient, readyToStart = common.InitSuite() tracerFactory := &common.TracerFactory{Tracer: tracer} - evaluationHandler := evaluation.NewHandler( - k8sManager.GetClient(), - eventsender.NewK8sSender(k8sManager.GetEventRecorderFor("test-appversion-controller")), - GinkgoLogr, - k8sManager.GetScheme(), - &telemetry.Handler{}) phaseHandler := phase.NewHandler( k8sManager.GetClient(), @@ -62,16 +55,15 @@ var _ = BeforeSuite(func() { // //setup controllers here controller := &keptnappversion.KeptnAppVersionReconciler{ - Client: k8sManager.GetClient(), - Scheme: k8sManager.GetScheme(), - EventSender: eventsender.NewK8sSender(k8sManager.GetEventRecorderFor("test-appversion-controller")), - Log: GinkgoLogr, - Meters: common.InitKeptnMeters(), - SpanHandler: &telemetry.Handler{}, - TracerFactory: tracerFactory, - EvaluationHandler: evaluationHandler, - PhaseHandler: phaseHandler, - Config: config.Instance(), + Client: k8sManager.GetClient(), + Scheme: k8sManager.GetScheme(), + EventSender: eventsender.NewK8sSender(k8sManager.GetEventRecorderFor("test-appversion-controller")), + Log: GinkgoLogr, + Meters: common.InitKeptnMeters(), + SpanHandler: &telemetry.Handler{}, + TracerFactory: tracerFactory, + PhaseHandler: phaseHandler, + Config: config.Instance(), } Eventually(controller.SetupWithManager(k8sManager)).WithTimeout(30 * time.Second).WithPolling(time.Second).Should(Succeed()) close(readyToStart) diff --git a/lifecycle-operator/test/component/workloadversion/workloadversion_suite_test.go b/lifecycle-operator/test/component/workloadversion/workloadversion_suite_test.go index 6fc47b851b..b5bc75ee6e 100644 --- a/lifecycle-operator/test/component/workloadversion/workloadversion_suite_test.go +++ b/lifecycle-operator/test/component/workloadversion/workloadversion_suite_test.go @@ -7,7 +7,6 @@ import ( "time" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/config" - "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/evaluation" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/eventsender" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/phase" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" @@ -46,12 +45,6 @@ var _ = BeforeSuite(func() { eventSender := eventsender.NewK8sSender(k8sManager.GetEventRecorderFor("test-workloadversion-controller")) tracerFactory := &common.TracerFactory{Tracer: tracer} - evaluationHandler := evaluation.NewHandler( - k8sManager.GetClient(), - eventSender, - GinkgoLogr, - k8sManager.GetScheme(), - &telemetry.Handler{}) phaseHandler := phase.NewHandler( k8sManager.GetClient(), @@ -63,16 +56,15 @@ var _ = BeforeSuite(func() { // //setup controllers here config.Instance().SetDefaultNamespace(KeptnNamespace) controller := &keptnworkloadversion.KeptnWorkloadVersionReconciler{ - Client: k8sManager.GetClient(), - Scheme: k8sManager.GetScheme(), - EventSender: eventSender, - Log: GinkgoLogr, - Meters: common.InitKeptnMeters(), - SpanHandler: &telemetry.Handler{}, - TracerFactory: tracerFactory, - EvaluationHandler: evaluationHandler, - PhaseHandler: phaseHandler, - Config: config.Instance(), + Client: k8sManager.GetClient(), + Scheme: k8sManager.GetScheme(), + EventSender: eventSender, + Log: GinkgoLogr, + Meters: common.InitKeptnMeters(), + SpanHandler: &telemetry.Handler{}, + TracerFactory: tracerFactory, + PhaseHandler: phaseHandler, + Config: config.Instance(), } Eventually(controller.SetupWithManager(k8sManager)).WithTimeout(30 * time.Second).WithPolling(time.Second).Should(Succeed()) close(readyToStart) From 8b491f9f14c5e25d6131071c800d7eaaa229328d Mon Sep 17 00:00:00 2001 From: RealAnna Date: Tue, 19 Mar 2024 12:32:27 +0100 Subject: [PATCH 7/7] fix: make Ondrej happy Signed-off-by: RealAnna --- lifecycle-operator/controllers/common/evaluation/handler.go | 2 +- .../controllers/common/evaluation/handler_test.go | 4 ++-- .../lifecycle/keptnappversion/reconcile_prepostevaluation.go | 2 +- .../keptnworkloadversion/reconcile_prepostevaluation.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lifecycle-operator/controllers/common/evaluation/handler.go b/lifecycle-operator/controllers/common/evaluation/handler.go index dbea8f7ae0..05562a8445 100644 --- a/lifecycle-operator/controllers/common/evaluation/handler.go +++ b/lifecycle-operator/controllers/common/evaluation/handler.go @@ -43,7 +43,7 @@ type CreateEvaluationAttributes struct { } // NewHandler creates a new instance of the Handler. -func NewHandler(client client.Client, eventSender eventsender.IEvent, tracer telemetry.ITracer, log logr.Logger, scheme *runtime.Scheme, spanHandler telemetry.ISpanHandler) Handler { +func NewHandler(client client.Client, eventSender eventsender.IEvent, log logr.Logger, tracer telemetry.ITracer, scheme *runtime.Scheme, spanHandler telemetry.ISpanHandler) Handler { return Handler{ Client: client, EventSender: eventSender, diff --git a/lifecycle-operator/controllers/common/evaluation/handler_test.go b/lifecycle-operator/controllers/common/evaluation/handler_test.go index 3adb7e15b7..19c341df07 100644 --- a/lifecycle-operator/controllers/common/evaluation/handler_test.go +++ b/lifecycle-operator/controllers/common/evaluation/handler_test.go @@ -411,8 +411,8 @@ func TestEvaluationHandler(t *testing.T) { handler := NewHandler( fake.NewClientBuilder().WithObjects(initObjs...).Build(), eventsender.NewK8sSender(fakeRecorder), - noop.NewTracerProvider().Tracer("tracer"), ctrl.Log.WithName("controller"), + noop.NewTracerProvider().Tracer("tracer"), scheme.Scheme, &spanHandlerMock) status, summary, err := handler.ReconcileEvaluations(context.TODO(), context.TODO(), tt.object, tt.createAttr) @@ -494,8 +494,8 @@ func TestEvaluationHandler_createEvaluation(t *testing.T) { handler := NewHandler( fake.NewClientBuilder().Build(), eventsender.NewK8sSender(record.NewFakeRecorder(100)), - noop.NewTracerProvider().Tracer("tracer"), ctrl.Log.WithName("controller"), + noop.NewTracerProvider().Tracer("tracer"), scheme.Scheme, &telemetryfake.ISpanHandlerMock{}) diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_prepostevaluation.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_prepostevaluation.go index 7ed123d888..2e6953c2e1 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_prepostevaluation.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_prepostevaluation.go @@ -18,8 +18,8 @@ func (r *KeptnAppVersionReconciler) reconcilePrePostEvaluation(ctx context.Conte evaluationHandler := evaluation.NewHandler( r.Client, r.EventSender, - r.getTracer(), r.Log, + r.getTracer(), r.Client.Scheme(), r.SpanHandler, ) diff --git a/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/reconcile_prepostevaluation.go b/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/reconcile_prepostevaluation.go index 2601d4c899..bf3e818dc9 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/reconcile_prepostevaluation.go +++ b/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/reconcile_prepostevaluation.go @@ -19,8 +19,8 @@ func (r *KeptnWorkloadVersionReconciler) reconcilePrePostEvaluation(ctx context. evaluationHandler := evaluation.NewHandler( r.Client, r.EventSender, - r.getTracer(), r.Log, + r.getTracer(), r.Client.Scheme(), r.SpanHandler, )