From cd76d4b3b69d3130665f7b2b4f906ca5f9dd6a22 Mon Sep 17 00:00:00 2001 From: Giovanni Liva Date: Sun, 6 Aug 2023 14:23:19 +0200 Subject: [PATCH 1/5] feat: add cloud events endpoint to config Signed-off-by: Giovanni Liva --- .../apis/options/v1alpha1/keptnconfig_types.go | 5 +++++ .../controllers/common/config/config.go | 11 +++++++++++ .../controllers/options/keptnconfig_controller.go | 12 ++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lifecycle-operator/apis/options/v1alpha1/keptnconfig_types.go b/lifecycle-operator/apis/options/v1alpha1/keptnconfig_types.go index 50d72d5eae..4428c70cfe 100644 --- a/lifecycle-operator/apis/options/v1alpha1/keptnconfig_types.go +++ b/lifecycle-operator/apis/options/v1alpha1/keptnconfig_types.go @@ -31,11 +31,16 @@ type KeptnConfigSpec struct { // OTelCollectorUrl can be used to set the Open Telemetry collector that the lifecycle operator should use // +optional OTelCollectorUrl string `json:"OTelCollectorUrl,omitempty"` + // KeptnAppCreationRequestTimeoutSeconds is used to set the interval in which automatic app discovery // searches for workload to put into the same auto-generated KeptnApp // +kubebuilder:default:=30 // +optional KeptnAppCreationRequestTimeoutSeconds uint `json:"keptnAppCreationRequestTimeoutSeconds,omitempty"` + + // CloudEventsEndpoint can be used to set the endpoint where Cloud Events should be posted by the lifecycle operator + // +optional + CloudEventsEndpoint string `json:"cloudEventsEndpoint,omitempty"` } // +kubebuilder:object:root=true diff --git a/lifecycle-operator/controllers/common/config/config.go b/lifecycle-operator/controllers/common/config/config.go index c2df8f2b85..043edb4348 100644 --- a/lifecycle-operator/controllers/common/config/config.go +++ b/lifecycle-operator/controllers/common/config/config.go @@ -11,10 +11,13 @@ const defaultKeptnAppCreationRequestTimeout = 30 * time.Second type IConfig interface { SetCreationRequestTimeout(value time.Duration) GetCreationRequestTimeout() time.Duration + SetCloudEventsEndpoint(endpoint string) + GetCloudEventsEndpoint() string } type ControllerConfig struct { keptnAppCreationRequestTimeout time.Duration + cloudEventsEndpoint string } var instance *ControllerConfig @@ -34,3 +37,11 @@ func (o *ControllerConfig) SetCreationRequestTimeout(value time.Duration) { func (o *ControllerConfig) GetCreationRequestTimeout() time.Duration { return o.keptnAppCreationRequestTimeout } + +func (o *ControllerConfig) SetCloudEventsEndpoint(endpoint string) { + o.cloudEventsEndpoint = endpoint +} + +func (o *ControllerConfig) GetCloudEventsEndpoint() string { + return o.cloudEventsEndpoint +} diff --git a/lifecycle-operator/controllers/options/keptnconfig_controller.go b/lifecycle-operator/controllers/options/keptnconfig_controller.go index 8af6e775ba..55ec7d459b 100644 --- a/lifecycle-operator/controllers/options/keptnconfig_controller.go +++ b/lifecycle-operator/controllers/options/keptnconfig_controller.go @@ -19,6 +19,7 @@ package options import ( "context" "fmt" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/config" "time" "github.com/go-logr/logr" @@ -49,8 +50,8 @@ type KeptnConfigReconciler struct { func (r *KeptnConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { r.Log.Info("Searching for KeptnConfig") - config := &optionsv1alpha1.KeptnConfig{} - err := r.Get(ctx, req.NamespacedName, config) + cfg := &optionsv1alpha1.KeptnConfig{} + err := r.Get(ctx, req.NamespacedName, cfg) if errors.IsNotFound(err) { return reconcile.Result{}, nil } @@ -63,12 +64,15 @@ func (r *KeptnConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) r.initConfig() } - result, err := r.reconcileOtelCollectorUrl(config) + result, err := r.reconcileOtelCollectorUrl(cfg) if err != nil { return result, err } + // reconcile config values + cfgInstance := config.Instance() + cfgInstance.SetCreationRequestTimeout(time.Duration(cfg.Spec.KeptnAppCreationRequestTimeoutSeconds) * time.Second) - r.LastAppliedSpec = &config.Spec + r.LastAppliedSpec = &cfg.Spec return ctrl.Result{}, nil } From e0faf35f350218984437973f014297b5f133e243 Mon Sep 17 00:00:00 2001 From: Giovanni Liva Date: Sun, 6 Aug 2023 17:11:16 +0200 Subject: [PATCH 2/5] chore: refactoring eventing and telemetry Signed-off-by: Giovanni Liva --- .../options/v1alpha1/keptnconfig_types.go | 5 --- .../controllers/common/config/config.go | 11 ------- .../controllers/common/evaluationhandler.go | 11 ++++--- .../controllers/common/eventsender.go | 31 ++++++++++++++----- .../controllers/common/eventsender_test.go | 4 +-- .../controllers/common/phasehandler.go | 13 ++++---- .../controllers/common/phasehandler_test.go | 15 ++++----- .../controllers/common/taskhandler.go | 9 +++--- .../common/{ => telemetry}/metrics.go | 2 +- .../common/{ => telemetry}/metrics_test.go | 2 +- .../common/{ => telemetry}/otel_utils.go | 2 +- .../common/{ => telemetry}/otel_utils_test.go | 2 +- .../common/{ => telemetry}/spanhandler.go | 2 +- .../{ => telemetry}/spanhandler_test.go | 2 +- .../common/{ => telemetry}/tracer.go | 2 +- .../lifecycle/keptnapp/controller.go | 11 ++++--- .../lifecycle/keptnappversion/controller.go | 9 +++--- .../reconcile_workloadsstate.go | 2 +- .../lifecycle/keptnevaluation/controller.go | 13 ++++---- .../lifecycle/keptntask/controller.go | 7 +++-- .../lifecycle/keptntask/job_runner_builder.go | 2 +- .../lifecycle/keptntask/job_utils.go | 4 +-- .../lifecycle/keptntask/runtime_builder.go | 6 ++-- .../keptntaskdefinition/controller.go | 2 +- .../keptntaskdefinition/reconcile_function.go | 4 +-- .../lifecycle/keptnworkload/controller.go | 9 +++--- .../keptnworkloadinstance/controller.go | 17 +++++----- .../options/keptnconfig_controller.go | 4 +-- lifecycle-operator/main.go | 21 +++++++------ .../pod_mutator/pod_mutating_webhook.go | 8 ++--- 30 files changed, 121 insertions(+), 111 deletions(-) rename lifecycle-operator/controllers/common/{ => telemetry}/metrics.go (99%) rename lifecycle-operator/controllers/common/{ => telemetry}/metrics_test.go (99%) rename lifecycle-operator/controllers/common/{ => telemetry}/otel_utils.go (99%) rename lifecycle-operator/controllers/common/{ => telemetry}/otel_utils_test.go (99%) rename lifecycle-operator/controllers/common/{ => telemetry}/spanhandler.go (99%) rename lifecycle-operator/controllers/common/{ => telemetry}/spanhandler_test.go (99%) rename lifecycle-operator/controllers/common/{ => telemetry}/tracer.go (94%) diff --git a/lifecycle-operator/apis/options/v1alpha1/keptnconfig_types.go b/lifecycle-operator/apis/options/v1alpha1/keptnconfig_types.go index 4428c70cfe..50d72d5eae 100644 --- a/lifecycle-operator/apis/options/v1alpha1/keptnconfig_types.go +++ b/lifecycle-operator/apis/options/v1alpha1/keptnconfig_types.go @@ -31,16 +31,11 @@ type KeptnConfigSpec struct { // OTelCollectorUrl can be used to set the Open Telemetry collector that the lifecycle operator should use // +optional OTelCollectorUrl string `json:"OTelCollectorUrl,omitempty"` - // KeptnAppCreationRequestTimeoutSeconds is used to set the interval in which automatic app discovery // searches for workload to put into the same auto-generated KeptnApp // +kubebuilder:default:=30 // +optional KeptnAppCreationRequestTimeoutSeconds uint `json:"keptnAppCreationRequestTimeoutSeconds,omitempty"` - - // CloudEventsEndpoint can be used to set the endpoint where Cloud Events should be posted by the lifecycle operator - // +optional - CloudEventsEndpoint string `json:"cloudEventsEndpoint,omitempty"` } // +kubebuilder:object:root=true diff --git a/lifecycle-operator/controllers/common/config/config.go b/lifecycle-operator/controllers/common/config/config.go index 043edb4348..c2df8f2b85 100644 --- a/lifecycle-operator/controllers/common/config/config.go +++ b/lifecycle-operator/controllers/common/config/config.go @@ -11,13 +11,10 @@ const defaultKeptnAppCreationRequestTimeout = 30 * time.Second type IConfig interface { SetCreationRequestTimeout(value time.Duration) GetCreationRequestTimeout() time.Duration - SetCloudEventsEndpoint(endpoint string) - GetCloudEventsEndpoint() string } type ControllerConfig struct { keptnAppCreationRequestTimeout time.Duration - cloudEventsEndpoint string } var instance *ControllerConfig @@ -37,11 +34,3 @@ func (o *ControllerConfig) SetCreationRequestTimeout(value time.Duration) { func (o *ControllerConfig) GetCreationRequestTimeout() time.Duration { return o.keptnAppCreationRequestTimeout } - -func (o *ControllerConfig) SetCloudEventsEndpoint(endpoint string) { - o.cloudEventsEndpoint = endpoint -} - -func (o *ControllerConfig) GetCloudEventsEndpoint() string { - return o.cloudEventsEndpoint -} diff --git a/lifecycle-operator/controllers/common/evaluationhandler.go b/lifecycle-operator/controllers/common/evaluationhandler.go index 8a889b133f..4f993e406e 100644 --- a/lifecycle-operator/controllers/common/evaluationhandler.go +++ b/lifecycle-operator/controllers/common/evaluationhandler.go @@ -8,6 +8,7 @@ import ( "github.com/go-logr/logr" klcv1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/lifecycle/interfaces" "go.opentelemetry.io/otel/codes" @@ -21,11 +22,11 @@ import ( type EvaluationHandler struct { client.Client - EventSender EventSender + EventSender IEvent Log logr.Logger Tracer trace.Tracer Scheme *runtime.Scheme - SpanHandler ISpanHandler + SpanHandler telemetry.ISpanHandler } type CreateEvaluationAttributes struct { @@ -55,7 +56,7 @@ func (r EvaluationHandler) ReconcileEvaluations(ctx context.Context, phaseCtx co evaluationExists := false if oldstatus != evaluationStatus.Status { - r.EventSender.SendK8sEvent(apicommon.PhaseReconcileEvaluation, "Normal", reconcileObject, apicommon.PhaseStateStatusChanged, fmt.Sprintf("evaluation status changed from %s to %s", oldstatus, evaluationStatus.Status), piWrapper.GetVersion()) + r.EventSender.SendEvent(apicommon.PhaseReconcileEvaluation, "Normal", reconcileObject, apicommon.PhaseStateStatusChanged, fmt.Sprintf("evaluation status changed from %s to %s", oldstatus, evaluationStatus.Status), piWrapper.GetVersion()) } // Check if evaluation has already succeeded or failed @@ -126,7 +127,7 @@ func (r EvaluationHandler) CreateKeptnEvaluation(ctx context.Context, namespace err = r.Client.Create(ctx, &newEvaluation) if err != nil { r.Log.Error(err, "could not create KeptnEvaluation") - r.EventSender.SendK8sEvent(phase, "Warning", reconcileObject, apicommon.PhaseStateFailed, "could not create KeptnEvaluation", piWrapper.GetVersion()) + r.EventSender.SendEvent(phase, "Warning", reconcileObject, apicommon.PhaseStateFailed, "could not create KeptnEvaluation", piWrapper.GetVersion()) return "", err } @@ -142,7 +143,7 @@ func (r EvaluationHandler) emitEvaluationFailureEvents(evaluation *klcv1alpha3.K k8sEventMessage = fmt.Sprintf("%s\n%s", k8sEventMessage, msg) } } - r.EventSender.SendK8sEvent(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateFailed, k8sEventMessage, piWrapper.GetVersion()) + r.EventSender.SendEvent(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateFailed, k8sEventMessage, piWrapper.GetVersion()) } func (r EvaluationHandler) setupEvaluations(evaluationCreateAttributes CreateEvaluationAttributes, piWrapper *interfaces.PhaseItemWrapper) ([]string, []klcv1alpha3.ItemStatus) { diff --git a/lifecycle-operator/controllers/common/eventsender.go b/lifecycle-operator/controllers/common/eventsender.go index cce0c7ae2c..2b7edb1b1a 100644 --- a/lifecycle-operator/controllers/common/eventsender.go +++ b/lifecycle-operator/controllers/common/eventsender.go @@ -2,25 +2,40 @@ package common import ( "fmt" - apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client" ) -type EventSender struct { +//go:generate moq -pkg fake -skip-ensure -out ./fake/event_mock.go . IEvent:MockEvent +type IEvent interface { + SendEvent(phase apicommon.KeptnPhaseType, eventType string, reconcileObject client.Object, status string, message string, version string) +} + +// ===== Main ===== + +func NewEventSender(recorder record.EventRecorder) IEvent { + return newK8sSender(recorder) +} + +// ===== Cloud Event Sender ===== +// TODO: implement Cloud Event logic + +// ===== K8s Event Sender ===== + +type k8sEvent struct { recorder record.EventRecorder } -func NewEventSender(recorder record.EventRecorder) EventSender { - return EventSender{ +func newK8sSender(recorder record.EventRecorder) IEvent { + return &k8sEvent{ recorder: recorder, } } -// SendK8sEvent creates k8s Event and adds it to Eventqueue -func (s *EventSender) SendK8sEvent(phase apicommon.KeptnPhaseType, eventType string, reconcileObject client.Object, shortReason string, longReason string, version string) { - msg := setEventMessage(phase, reconcileObject, longReason, version) +// SendEvent creates k8s Event and adds it to Eventqueue +func (s *k8sEvent) SendEvent(phase apicommon.KeptnPhaseType, eventType string, reconcileObject client.Object, status string, message string, version string) { + msg := setEventMessage(phase, reconcileObject, message, version) annotations := setAnnotations(reconcileObject, phase) - s.recorder.AnnotatedEventf(reconcileObject, annotations, eventType, fmt.Sprintf("%s%s", phase.ShortName, shortReason), msg) + s.recorder.AnnotatedEventf(reconcileObject, annotations, eventType, fmt.Sprintf("%s%s", phase.ShortName, status), msg) } diff --git a/lifecycle-operator/controllers/common/eventsender_test.go b/lifecycle-operator/controllers/common/eventsender_test.go index 715178b2df..c1b5241fc0 100644 --- a/lifecycle-operator/controllers/common/eventsender_test.go +++ b/lifecycle-operator/controllers/common/eventsender_test.go @@ -13,9 +13,9 @@ import ( func TestEventSender_SendK8sEvent(t *testing.T) { fakeRecorder := record.NewFakeRecorder(100) - eventSender := NewEventSender(fakeRecorder) + eventSender := newK8sSender(fakeRecorder) - eventSender.SendK8sEvent(common.PhaseAppDeployment, "pre-event", &v1alpha3.KeptnAppVersion{ + eventSender.SendEvent(common.PhaseAppDeployment, "pre-event", &v1alpha3.KeptnAppVersion{ ObjectMeta: v1.ObjectMeta{ Name: "app", Namespace: "ns", diff --git a/lifecycle-operator/controllers/common/phasehandler.go b/lifecycle-operator/controllers/common/phasehandler.go index 80b9556351..4327897ee3 100644 --- a/lifecycle-operator/controllers/common/phasehandler.go +++ b/lifecycle-operator/controllers/common/phasehandler.go @@ -6,6 +6,7 @@ import ( "github.com/go-logr/logr" apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/lifecycle/interfaces" "go.opentelemetry.io/otel/codes" @@ -16,9 +17,9 @@ import ( type PhaseHandler struct { client.Client - EventSender EventSender + EventSender IEvent Log logr.Logger - SpanHandler ISpanHandler + SpanHandler telemetry.ISpanHandler } type PhaseResult struct { @@ -39,7 +40,7 @@ func (r PhaseHandler) HandlePhase(ctx context.Context, ctxTrace context.Context, return &PhaseResult{Continue: false, Result: ctrl.Result{}}, nil } if oldPhase != phase.ShortName { - r.EventSender.SendK8sEvent(phase, "Normal", reconcileObject, apicommon.PhaseStateStarted, "has started", piWrapper.GetVersion()) + r.EventSender.SendEvent(phase, "Normal", reconcileObject, apicommon.PhaseStateStarted, "has started", piWrapper.GetVersion()) piWrapper.SetCurrentPhase(phase.ShortName) } @@ -51,7 +52,7 @@ func (r PhaseHandler) HandlePhase(ctx context.Context, ctxTrace context.Context, state, err := reconcilePhase(spanPhaseCtx) if err != nil { spanPhaseTrace.AddEvent(phase.LongName + " could not get reconciled") - r.EventSender.SendK8sEvent(phase, "Warning", reconcileObject, apicommon.PhaseStateReconcileError, "could not get reconciled", piWrapper.GetVersion()) + r.EventSender.SendEvent(phase, "Warning", reconcileObject, apicommon.PhaseStateReconcileError, "could not get reconciled", piWrapper.GetVersion()) span.SetStatus(codes.Error, err.Error()) return &PhaseResult{Continue: false, Result: requeueResult}, err } @@ -88,7 +89,7 @@ func (r PhaseHandler) handleCompletedPhase(state apicommon.KeptnState, piWrapper if err := r.SpanHandler.UnbindSpan(reconcileObject, phase.ShortName); err != nil { r.Log.Error(err, controllererrors.ErrCouldNotUnbindSpan, reconcileObject.GetName()) } - r.EventSender.SendK8sEvent(phase, "Warning", reconcileObject, apicommon.PhaseStateFailed, "has failed", piWrapper.GetVersion()) + r.EventSender.SendEvent(phase, "Warning", reconcileObject, apicommon.PhaseStateFailed, "has failed", piWrapper.GetVersion()) piWrapper.DeprecateRemainingPhases(phase) return &PhaseResult{Continue: false, Result: ctrl.Result{}}, nil } @@ -100,7 +101,7 @@ func (r PhaseHandler) handleCompletedPhase(state apicommon.KeptnState, piWrapper if err := r.SpanHandler.UnbindSpan(reconcileObject, phase.ShortName); err != nil { r.Log.Error(err, controllererrors.ErrCouldNotUnbindSpan, reconcileObject.GetName()) } - r.EventSender.SendK8sEvent(phase, "Normal", reconcileObject, apicommon.PhaseStateFinished, "has finished", piWrapper.GetVersion()) + r.EventSender.SendEvent(phase, "Normal", reconcileObject, apicommon.PhaseStateFinished, "has finished", piWrapper.GetVersion()) return &PhaseResult{Continue: true, Result: ctrl.Result{Requeue: true, RequeueAfter: 5 * time.Second}}, nil } diff --git a/lifecycle-operator/controllers/common/phasehandler_test.go b/lifecycle-operator/controllers/common/phasehandler_test.go index 4b5db6ee1d..09a73d0ba6 100644 --- a/lifecycle-operator/controllers/common/phasehandler_test.go +++ b/lifecycle-operator/controllers/common/phasehandler_test.go @@ -8,6 +8,7 @@ import ( "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/trace" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -33,7 +34,7 @@ func TestPhaseHandler(t *testing.T) { { name: "deprecated", handler: PhaseHandler{ - SpanHandler: &SpanHandler{}, + SpanHandler: &telemetry.SpanHandler{}, }, object: &v1alpha3.KeptnAppVersion{ Status: v1alpha3.KeptnAppVersionStatus{ @@ -51,7 +52,7 @@ func TestPhaseHandler(t *testing.T) { { name: "reconcilePhase error", handler: PhaseHandler{ - SpanHandler: &SpanHandler{}, + SpanHandler: &telemetry.SpanHandler{}, Log: ctrl.Log.WithName("controller"), EventSender: NewEventSender(record.NewFakeRecorder(100)), Client: fake.NewClientBuilder().WithScheme(scheme.Scheme).Build(), @@ -78,7 +79,7 @@ func TestPhaseHandler(t *testing.T) { { name: "reconcilePhase pending state", handler: PhaseHandler{ - SpanHandler: &SpanHandler{}, + SpanHandler: &telemetry.SpanHandler{}, Log: ctrl.Log.WithName("controller"), EventSender: NewEventSender(record.NewFakeRecorder(100)), Client: fake.NewClientBuilder().WithScheme(scheme.Scheme).Build(), @@ -105,7 +106,7 @@ func TestPhaseHandler(t *testing.T) { { name: "reconcilePhase progressing state", handler: PhaseHandler{ - SpanHandler: &SpanHandler{}, + SpanHandler: &telemetry.SpanHandler{}, Log: ctrl.Log.WithName("controller"), EventSender: NewEventSender(record.NewFakeRecorder(100)), Client: fake.NewClientBuilder().WithScheme(scheme.Scheme).Build(), @@ -132,7 +133,7 @@ func TestPhaseHandler(t *testing.T) { { name: "reconcilePhase succeeded state", handler: PhaseHandler{ - SpanHandler: &SpanHandler{}, + SpanHandler: &telemetry.SpanHandler{}, Log: ctrl.Log.WithName("controller"), EventSender: NewEventSender(record.NewFakeRecorder(100)), Client: fake.NewClientBuilder().WithScheme(scheme.Scheme).Build(), @@ -159,7 +160,7 @@ func TestPhaseHandler(t *testing.T) { { name: "reconcilePhase failed state", handler: PhaseHandler{ - SpanHandler: &SpanHandler{}, + SpanHandler: &telemetry.SpanHandler{}, Log: ctrl.Log.WithName("controller"), EventSender: NewEventSender(record.NewFakeRecorder(100)), Client: fake.NewClientBuilder().WithScheme(scheme.Scheme).Build(), @@ -187,7 +188,7 @@ func TestPhaseHandler(t *testing.T) { { name: "reconcilePhase unknown state", handler: PhaseHandler{ - SpanHandler: &SpanHandler{}, + SpanHandler: &telemetry.SpanHandler{}, Log: ctrl.Log.WithName("controller"), EventSender: NewEventSender(record.NewFakeRecorder(100)), Client: fake.NewClientBuilder().WithScheme(scheme.Scheme).Build(), diff --git a/lifecycle-operator/controllers/common/taskhandler.go b/lifecycle-operator/controllers/common/taskhandler.go index 8713b12da0..54c010ef58 100644 --- a/lifecycle-operator/controllers/common/taskhandler.go +++ b/lifecycle-operator/controllers/common/taskhandler.go @@ -8,6 +8,7 @@ import ( "github.com/go-logr/logr" klcv1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/lifecycle/interfaces" "go.opentelemetry.io/otel/codes" @@ -21,11 +22,11 @@ import ( type TaskHandler struct { client.Client - EventSender EventSender + EventSender IEvent Log logr.Logger Tracer trace.Tracer Scheme *runtime.Scheme - SpanHandler ISpanHandler + SpanHandler telemetry.ISpanHandler } type CreateTaskAttributes struct { @@ -57,7 +58,7 @@ func (r TaskHandler) ReconcileTasks(ctx context.Context, phaseCtx context.Contex taskExists := false if oldstatus != taskStatus.Status { - r.EventSender.SendK8sEvent(phase, "Normal", reconcileObject, apicommon.PhaseStateStatusChanged, fmt.Sprintf("task status changed from %s to %s", oldstatus, taskStatus.Status), piWrapper.GetVersion()) + r.EventSender.SendEvent(phase, "Normal", reconcileObject, apicommon.PhaseStateStatusChanged, fmt.Sprintf("task status changed from %s to %s", oldstatus, taskStatus.Status), piWrapper.GetVersion()) } // Check if task has already succeeded or failed @@ -130,7 +131,7 @@ func (r TaskHandler) CreateKeptnTask(ctx context.Context, namespace string, reco err = r.Client.Create(ctx, &newTask) if err != nil { r.Log.Error(err, "could not create KeptnTask") - r.EventSender.SendK8sEvent(phase, "Warning", reconcileObject, apicommon.PhaseStateFailed, "could not create KeptnTask", piWrapper.GetVersion()) + r.EventSender.SendEvent(phase, "Warning", reconcileObject, apicommon.PhaseStateFailed, "could not create KeptnTask", piWrapper.GetVersion()) return "", err } diff --git a/lifecycle-operator/controllers/common/metrics.go b/lifecycle-operator/controllers/common/telemetry/metrics.go similarity index 99% rename from lifecycle-operator/controllers/common/metrics.go rename to lifecycle-operator/controllers/common/telemetry/metrics.go index 7da45afd30..d96358beec 100644 --- a/lifecycle-operator/controllers/common/metrics.go +++ b/lifecycle-operator/controllers/common/telemetry/metrics.go @@ -1,4 +1,4 @@ -package common +package telemetry import ( "context" diff --git a/lifecycle-operator/controllers/common/metrics_test.go b/lifecycle-operator/controllers/common/telemetry/metrics_test.go similarity index 99% rename from lifecycle-operator/controllers/common/metrics_test.go rename to lifecycle-operator/controllers/common/telemetry/metrics_test.go index 45a77d703e..3f6ec0bc3e 100644 --- a/lifecycle-operator/controllers/common/metrics_test.go +++ b/lifecycle-operator/controllers/common/telemetry/metrics_test.go @@ -1,4 +1,4 @@ -package common +package telemetry import ( "context" diff --git a/lifecycle-operator/controllers/common/otel_utils.go b/lifecycle-operator/controllers/common/telemetry/otel_utils.go similarity index 99% rename from lifecycle-operator/controllers/common/otel_utils.go rename to lifecycle-operator/controllers/common/telemetry/otel_utils.go index 695dd39bfd..abaf933477 100644 --- a/lifecycle-operator/controllers/common/otel_utils.go +++ b/lifecycle-operator/controllers/common/telemetry/otel_utils.go @@ -1,4 +1,4 @@ -package common +package telemetry import ( "context" diff --git a/lifecycle-operator/controllers/common/otel_utils_test.go b/lifecycle-operator/controllers/common/telemetry/otel_utils_test.go similarity index 99% rename from lifecycle-operator/controllers/common/otel_utils_test.go rename to lifecycle-operator/controllers/common/telemetry/otel_utils_test.go index 769f5fce85..a8d9aa6875 100644 --- a/lifecycle-operator/controllers/common/otel_utils_test.go +++ b/lifecycle-operator/controllers/common/telemetry/otel_utils_test.go @@ -1,4 +1,4 @@ -package common +package telemetry import ( "net" diff --git a/lifecycle-operator/controllers/common/spanhandler.go b/lifecycle-operator/controllers/common/telemetry/spanhandler.go similarity index 99% rename from lifecycle-operator/controllers/common/spanhandler.go rename to lifecycle-operator/controllers/common/telemetry/spanhandler.go index 7560b463db..ae6342e7e6 100644 --- a/lifecycle-operator/controllers/common/spanhandler.go +++ b/lifecycle-operator/controllers/common/telemetry/spanhandler.go @@ -1,4 +1,4 @@ -package common +package telemetry import ( "context" diff --git a/lifecycle-operator/controllers/common/spanhandler_test.go b/lifecycle-operator/controllers/common/telemetry/spanhandler_test.go similarity index 99% rename from lifecycle-operator/controllers/common/spanhandler_test.go rename to lifecycle-operator/controllers/common/telemetry/spanhandler_test.go index 1ba377c446..e9d491a732 100644 --- a/lifecycle-operator/controllers/common/spanhandler_test.go +++ b/lifecycle-operator/controllers/common/telemetry/spanhandler_test.go @@ -1,4 +1,4 @@ -package common +package telemetry import ( "context" diff --git a/lifecycle-operator/controllers/common/tracer.go b/lifecycle-operator/controllers/common/telemetry/tracer.go similarity index 94% rename from lifecycle-operator/controllers/common/tracer.go rename to lifecycle-operator/controllers/common/telemetry/tracer.go index 4fda3a5a96..6c86418830 100644 --- a/lifecycle-operator/controllers/common/tracer.go +++ b/lifecycle-operator/controllers/common/telemetry/tracer.go @@ -1,4 +1,4 @@ -package common +package telemetry import "go.opentelemetry.io/otel/trace" diff --git a/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go b/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go index ea52347ed0..6b7227a62a 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go @@ -19,6 +19,7 @@ package keptnapp import ( "context" "fmt" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "github.com/go-logr/logr" klcv1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" @@ -47,9 +48,9 @@ const traceComponentName = "keptn/lifecycle-operator/app" type KeptnAppReconciler struct { client.Client Scheme *runtime.Scheme - EventSender controllercommon.EventSender + EventSender controllercommon.IEvent Log logr.Logger - TracerFactory controllercommon.TracerFactory + TracerFactory telemetry.TracerFactory } // +kubebuilder:rbac:groups=lifecycle.keptn.sh,resources=keptnapps,verbs=get;list;watch;create;update;patch;delete @@ -105,7 +106,7 @@ func (r *KeptnAppReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c if err != nil { r.Log.Error(err, "could not create AppVersion") span.SetStatus(codes.Error, err.Error()) - r.EventSender.SendK8sEvent(common.PhaseCreateAppVersion, "Warning", appVersion, common.PhaseStateFailed, "Could not create KeptnAppVersion", appVersion.Spec.Version) + r.EventSender.SendEvent(common.PhaseCreateAppVersion, "Warning", appVersion, common.PhaseStateFailed, "Could not create KeptnAppVersion", appVersion.Spec.Version) return ctrl.Result{}, err } @@ -171,7 +172,7 @@ func (r *KeptnAppReconciler) handleGenerationBump(ctx context.Context, app *klcv if app.Generation != 1 { if err := r.deprecateAppVersions(ctx, app); err != nil { r.Log.Error(err, "could not deprecate appVersions for appVersion %s", app.GetAppVersionName()) - r.EventSender.SendK8sEvent(common.PhaseDeprecateAppVersion, "Warning", app, common.PhaseStateFailed, fmt.Sprintf("could not deprecate outdated revisions of KeptnAppVersion: %s", app.GetAppVersionName()), app.Spec.Version) + r.EventSender.SendEvent(common.PhaseDeprecateAppVersion, "Warning", app, common.PhaseStateFailed, fmt.Sprintf("could not deprecate outdated revisions of KeptnAppVersion: %s", app.GetAppVersionName()), app.Spec.Version) return err } } @@ -200,6 +201,6 @@ func (r *KeptnAppReconciler) deprecateAppVersions(ctx context.Context, app *klcv return lastResultErr } -func (r *KeptnAppReconciler) getTracer() controllercommon.ITracer { +func (r *KeptnAppReconciler) getTracer() telemetry.ITracer { return r.TracerFactory.GetTracer(traceComponentName) } diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go index 7b081b128e..19e8446246 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go @@ -19,6 +19,7 @@ package keptnappversion import ( "context" "fmt" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "time" "github.com/go-logr/logr" @@ -47,10 +48,10 @@ type KeptnAppVersionReconciler struct { Scheme *runtime.Scheme client.Client Log logr.Logger - EventSender controllercommon.EventSender - TracerFactory controllercommon.TracerFactory + EventSender controllercommon.IEvent + TracerFactory telemetry.TracerFactory Meters apicommon.KeptnMeters - SpanHandler controllercommon.ISpanHandler + SpanHandler telemetry.ISpanHandler } // +kubebuilder:rbac:groups=lifecycle.keptn.sh,resources=keptnappversions,verbs=get;list;watch;create;update;patch;delete @@ -181,7 +182,7 @@ func (r *KeptnAppVersionReconciler) finishKeptnAppVersionReconcile(ctx context.C return ctrl.Result{Requeue: true}, err } - r.EventSender.SendK8sEvent(apicommon.PhaseAppCompleted, "Normal", appVersion, apicommon.PhaseStateFinished, "has finished", appVersion.GetVersion()) + r.EventSender.SendEvent(apicommon.PhaseAppCompleted, "Normal", appVersion, apicommon.PhaseStateFinished, "has finished", appVersion.GetVersion()) attrs := appVersion.GetMetricsAttributes() diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_workloadsstate.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_workloadsstate.go index f206ed6a4d..09297e6f7f 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_workloadsstate.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_workloadsstate.go @@ -41,7 +41,7 @@ func (r *KeptnAppVersionReconciler) reconcileWorkloads(ctx context.Context, appV } if !found { - r.EventSender.SendK8sEvent(phase, "Warning", appVersion, apicommon.PhaseStateNotFound, fmt.Sprintf("could not find KeptnWorkloadInstance for KeptnWorkload: %s ", w.Name), appVersion.GetVersion()) + r.EventSender.SendEvent(phase, "Warning", appVersion, apicommon.PhaseStateNotFound, fmt.Sprintf("could not find KeptnWorkloadInstance for KeptnWorkload: %s ", w.Name), appVersion.GetVersion()) } newStatus = append(newStatus, klcv1alpha3.WorkloadStatus{ diff --git a/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller.go b/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller.go index 6f8874a43b..9b51f8b76d 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller.go @@ -19,6 +19,7 @@ package keptnevaluation import ( "context" "fmt" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "time" "github.com/go-logr/logr" @@ -46,10 +47,10 @@ const traceComponentName = "keptn/lifecycle-operator/evaluation" type KeptnEvaluationReconciler struct { client.Client Scheme *runtime.Scheme - EventSender controllercommon.EventSender + EventSender controllercommon.IEvent Log logr.Logger Meters apicommon.KeptnMeters - TracerFactory controllercommon.TracerFactory + TracerFactory telemetry.TracerFactory Namespace string } @@ -138,7 +139,7 @@ func (r *KeptnEvaluationReconciler) handleEvaluationIncomplete(ctx context.Conte // Evaluation is uncompleted, update status anyway this avoids updating twice in case of completion err := r.Client.Status().Update(ctx, evaluation) if err != nil { - r.EventSender.SendK8sEvent(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateReconcileError, "could not update status", "") + r.EventSender.SendEvent(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateReconcileError, "could not update status", "") span.SetStatus(codes.Error, err.Error()) return err } @@ -148,7 +149,7 @@ func (r *KeptnEvaluationReconciler) handleEvaluationIncomplete(ctx context.Conte } func (r *KeptnEvaluationReconciler) handleEvaluationExceededRetries(ctx context.Context, evaluation *klcv1alpha3.KeptnEvaluation, span trace.Span) { - r.EventSender.SendK8sEvent(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateReconcileTimeout, "retryCount exceeded", "") + r.EventSender.SendEvent(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateReconcileTimeout, "retryCount exceeded", "") err := controllererrors.ErrRetryCountExceeded span.SetStatus(codes.Error, err.Error()) evaluation.Status.OverallStatus = apicommon.StateFailed @@ -237,7 +238,7 @@ func (r *KeptnEvaluationReconciler) updateFinishedEvaluationMetrics(ctx context. err := r.Client.Status().Update(ctx, evaluation) if err != nil { span.SetStatus(codes.Error, err.Error()) - r.EventSender.SendK8sEvent(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateReconcileError, "could not update status", "") + r.EventSender.SendEvent(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateReconcileError, "could not update status", "") return err } @@ -261,6 +262,6 @@ func (r *KeptnEvaluationReconciler) SetupWithManager(mgr ctrl.Manager) error { Complete(r) } -func (r *KeptnEvaluationReconciler) getTracer() controllercommon.ITracer { +func (r *KeptnEvaluationReconciler) getTracer() telemetry.ITracer { return r.TracerFactory.GetTracer(traceComponentName) } diff --git a/lifecycle-operator/controllers/lifecycle/keptntask/controller.go b/lifecycle-operator/controllers/lifecycle/keptntask/controller.go index 640c4f76d7..7768a764da 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntask/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptntask/controller.go @@ -18,6 +18,7 @@ package keptntask import ( "context" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "time" "github.com/go-logr/logr" @@ -43,10 +44,10 @@ const traceComponentName = "keptn/lifecycle-operator/task" type KeptnTaskReconciler struct { client.Client Scheme *runtime.Scheme - EventSender controllercommon.EventSender + EventSender controllercommon.IEvent Log logr.Logger Meters apicommon.KeptnMeters - TracerFactory controllercommon.TracerFactory + TracerFactory telemetry.TracerFactory } // +kubebuilder:rbac:groups=lifecycle.keptn.sh,resources=keptntasks,verbs=get;list;watch;create;update;patch;delete @@ -137,6 +138,6 @@ func (r *KeptnTaskReconciler) SetupWithManager(mgr ctrl.Manager) error { Complete(r) } -func (r *KeptnTaskReconciler) getTracer() controllercommon.ITracer { +func (r *KeptnTaskReconciler) getTracer() telemetry.ITracer { return r.TracerFactory.GetTracer(traceComponentName) } diff --git a/lifecycle-operator/controllers/lifecycle/keptntask/job_runner_builder.go b/lifecycle-operator/controllers/lifecycle/keptntask/job_runner_builder.go index fd741f91d7..ef2371014f 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntask/job_runner_builder.go +++ b/lifecycle-operator/controllers/lifecycle/keptntask/job_runner_builder.go @@ -20,7 +20,7 @@ type JobRunnerBuilder interface { // BuilderOptions contains everything needed to build the current job type BuilderOptions struct { client.Client - eventSender controllercommon.EventSender + eventSender controllercommon.IEvent req ctrl.Request Log logr.Logger task *klcv1alpha3.KeptnTask diff --git a/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go b/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go index 70c1d23e10..22290dfba7 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go +++ b/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go @@ -21,7 +21,7 @@ func (r *KeptnTaskReconciler) createJob(ctx context.Context, req ctrl.Request, t definition, err := controllercommon.GetTaskDefinition(r.Client, r.Log, ctx, task.Spec.TaskDefinition, req.Namespace) if err != nil { r.Log.Error(err, fmt.Sprintf("could not find KeptnTaskDefinition: %s ", task.Spec.TaskDefinition)) - r.EventSender.SendK8sEvent(apicommon.PhaseCreateTask, "Warning", task, apicommon.PhaseStateNotFound, fmt.Sprintf("could not find KeptnTaskDefinition: %s ", task.Spec.TaskDefinition), "") + r.EventSender.SendEvent(apicommon.PhaseCreateTask, "Warning", task, apicommon.PhaseStateNotFound, fmt.Sprintf("could not find KeptnTaskDefinition: %s ", task.Spec.TaskDefinition), "") return err } @@ -47,7 +47,7 @@ func (r *KeptnTaskReconciler) createFunctionJob(ctx context.Context, req ctrl.Re err = r.Client.Create(ctx, job) if err != nil { r.Log.Error(err, "could not create Job") - r.EventSender.SendK8sEvent(apicommon.PhaseCreateTask, "Warning", task, apicommon.PhaseStateFailed, fmt.Sprintf("could not create Job: %s ", task.Name), "") + r.EventSender.SendEvent(apicommon.PhaseCreateTask, "Warning", task, apicommon.PhaseStateFailed, fmt.Sprintf("could not create Job: %s ", task.Name), "") return job.Name, err } diff --git a/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder.go b/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder.go index 89505dea61..9b2e7d4fdb 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder.go +++ b/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder.go @@ -157,7 +157,7 @@ func (fb *RuntimeBuilder) getParams(ctx context.Context) (*RuntimeExecutionParam if len(fb.options.task.Spec.Parameters.Inline) > 0 { err = mergo.Merge(¶ms.Parameters, fb.options.task.Spec.Parameters.Inline) if err != nil { - fb.options.eventSender.SendK8sEvent(apicommon.PhaseCreateTask, "Warning", fb.options.task, apicommon.PhaseStateFailed, fmt.Sprintf("could not merge KeptnTaskDefinition: %s ", fb.options.task.Spec.TaskDefinition), "") + fb.options.eventSender.SendEvent(apicommon.PhaseCreateTask, "Warning", fb.options.task, apicommon.PhaseStateFailed, fmt.Sprintf("could not merge KeptnTaskDefinition: %s ", fb.options.task.Spec.TaskDefinition), "") return nil, err } } @@ -211,7 +211,7 @@ func (fb *RuntimeBuilder) handleParent(ctx context.Context, params *RuntimeExecu var parentJobParams RuntimeExecutionParams parentDefinition, err := controllercommon.GetTaskDefinition(fb.options.Client, fb.options.Log, ctx, fb.options.funcSpec.FunctionReference.Name, fb.options.req.Namespace) if err != nil { - fb.options.eventSender.SendK8sEvent(apicommon.PhaseCreateTask, "Warning", fb.options.task, apicommon.PhaseStateNotFound, fmt.Sprintf("could not find KeptnTaskDefinition: %s ", fb.options.task.Spec.TaskDefinition), "") + fb.options.eventSender.SendEvent(apicommon.PhaseCreateTask, "Warning", fb.options.task, apicommon.PhaseStateNotFound, fmt.Sprintf("could not find KeptnTaskDefinition: %s ", fb.options.task.Spec.TaskDefinition), "") return err } parSpec := controllercommon.GetRuntimeSpec(parentDefinition) @@ -223,7 +223,7 @@ func (fb *RuntimeBuilder) handleParent(ctx context.Context, params *RuntimeExecu // merge parameter to make sure we use child task data for env var and secrets err = mergo.Merge(params, parentJobParams) if err != nil { - fb.options.eventSender.SendK8sEvent(apicommon.PhaseCreateTask, "Warning", fb.options.task, apicommon.PhaseStateFailed, fmt.Sprintf("could not merge KeptnTaskDefinition: %s ", fb.options.task.Spec.TaskDefinition), "") + fb.options.eventSender.SendEvent(apicommon.PhaseCreateTask, "Warning", fb.options.task, apicommon.PhaseStateFailed, fmt.Sprintf("could not merge KeptnTaskDefinition: %s ", fb.options.task.Spec.TaskDefinition), "") return err } diff --git a/lifecycle-operator/controllers/lifecycle/keptntaskdefinition/controller.go b/lifecycle-operator/controllers/lifecycle/keptntaskdefinition/controller.go index 5e8aa6fd58..0dcb3daf01 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntaskdefinition/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptntaskdefinition/controller.go @@ -36,7 +36,7 @@ type KeptnTaskDefinitionReconciler struct { client.Client Scheme *runtime.Scheme Log logr.Logger - EventSender controllercommon.EventSender + EventSender controllercommon.IEvent } // +kubebuilder:rbac:groups=lifecycle.keptn.sh,resources=keptntaskdefinitions,verbs=get;list;watch;create;update;patch;delete diff --git a/lifecycle-operator/controllers/lifecycle/keptntaskdefinition/reconcile_function.go b/lifecycle-operator/controllers/lifecycle/keptntaskdefinition/reconcile_function.go index 1579c54401..4f1b9b9c85 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntaskdefinition/reconcile_function.go +++ b/lifecycle-operator/controllers/lifecycle/keptntaskdefinition/reconcile_function.go @@ -32,14 +32,14 @@ func (r *KeptnTaskDefinitionReconciler) reconcileConfigMap(ctx context.Context, err := r.Client.Create(ctx, functionCm) if err != nil { r.Log.Error(err, "could not create ConfigMap") - r.EventSender.SendK8sEvent(apicommon.PhaseReconcileTask, "Warning", functionCm, apicommon.PhaseStateFailed, "could not create configmap", "") + r.EventSender.SendEvent(apicommon.PhaseReconcileTask, "Warning", functionCm, apicommon.PhaseStateFailed, "could not create configmap", "") return } } else if !reflect.DeepEqual(cm, functionCm) && functionCm != nil { // cm and inline func exists but differ err := r.Client.Update(ctx, functionCm) if err != nil { r.Log.Error(err, "could not update ConfigMap") - r.EventSender.SendK8sEvent(apicommon.PhaseReconcileTask, "Warning", functionCm, apicommon.PhaseStateFailed, "could not update configmap", "") + r.EventSender.SendEvent(apicommon.PhaseReconcileTask, "Warning", functionCm, apicommon.PhaseStateFailed, "could not update configmap", "") return } } diff --git a/lifecycle-operator/controllers/lifecycle/keptnworkload/controller.go b/lifecycle-operator/controllers/lifecycle/keptnworkload/controller.go index d5439c9687..80619df6dc 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnworkload/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnworkload/controller.go @@ -19,6 +19,7 @@ package keptnworkload import ( "context" "fmt" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "github.com/go-logr/logr" klcv1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" @@ -46,9 +47,9 @@ const traceComponentName = "keptn/lifecycle-operator/workload" type KeptnWorkloadReconciler struct { client.Client Scheme *runtime.Scheme - EventSender controllercommon.EventSender + EventSender controllercommon.IEvent Log logr.Logger - TracerFactory controllercommon.TracerFactory + TracerFactory telemetry.TracerFactory } // +kubebuilder:rbac:groups=lifecycle.keptn.sh,resources=keptnworkloads,verbs=get;list;watch;create;update;patch;delete @@ -104,7 +105,7 @@ func (r *KeptnWorkloadReconciler) Reconcile(ctx context.Context, req ctrl.Reques if err != nil { r.Log.Error(err, "could not create WorkloadInstance") span.SetStatus(codes.Error, err.Error()) - r.EventSender.SendK8sEvent(apicommon.PhaseCreateWorklodInstance, "Warning", workloadInstance, apicommon.PhaseStateFailed, "could not create KeptnWorkloadInstance ", workloadInstance.Spec.Version) + r.EventSender.SendEvent(apicommon.PhaseCreateWorklodInstance, "Warning", workloadInstance, apicommon.PhaseStateFailed, "could not create KeptnWorkloadInstance ", workloadInstance.Spec.Version) return ctrl.Result{}, err } workload.Status.CurrentVersion = workload.Spec.Version @@ -161,6 +162,6 @@ func (r *KeptnWorkloadReconciler) createWorkloadInstance(ctx context.Context, wo return &workloadInstance, err } -func (r *KeptnWorkloadReconciler) getTracer() controllercommon.ITracer { +func (r *KeptnWorkloadReconciler) getTracer() telemetry.ITracer { return r.TracerFactory.GetTracer(traceComponentName) } diff --git a/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller.go b/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller.go index 255d4a9802..ff92590572 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller.go @@ -19,6 +19,7 @@ package keptnworkloadinstance import ( "context" "fmt" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "time" "github.com/go-logr/logr" @@ -46,11 +47,11 @@ const traceComponentName = "keptn/lifecycle-operator/workloadinstance" type KeptnWorkloadInstanceReconciler struct { client.Client Scheme *runtime.Scheme - EventSender controllercommon.EventSender + EventSender controllercommon.IEvent Log logr.Logger Meters apicommon.KeptnMeters - SpanHandler *controllercommon.SpanHandler - TracerFactory controllercommon.TracerFactory + SpanHandler *telemetry.SpanHandler + TracerFactory telemetry.TracerFactory } // +kubebuilder:rbac:groups=lifecycle.keptn.sh,resources=keptnworkloadinstances,verbs=get;list;watch;create;update;patch;delete @@ -190,7 +191,7 @@ func (r *KeptnWorkloadInstanceReconciler) finishKeptnWorkloadInstanceReconcile(c return ctrl.Result{Requeue: true}, err } - r.EventSender.SendK8sEvent(apicommon.PhaseWorkloadCompleted, "Normal", workloadInstance, apicommon.PhaseStateFinished, "has finished", workloadInstance.GetVersion()) + r.EventSender.SendEvent(apicommon.PhaseWorkloadCompleted, "Normal", workloadInstance, apicommon.PhaseStateFinished, "has finished", workloadInstance.GetVersion()) attrs := workloadInstance.GetMetricsAttributes() @@ -224,7 +225,7 @@ func (r *KeptnWorkloadInstanceReconciler) SetupWithManager(mgr ctrl.Manager) err func (r *KeptnWorkloadInstanceReconciler) sendUnfinishedPreEvaluationEvents(appPreEvalStatus apicommon.KeptnState, phase apicommon.KeptnPhaseType, workloadInstance *klcv1alpha3.KeptnWorkloadInstance) { if appPreEvalStatus.IsFailed() { - r.EventSender.SendK8sEvent(phase, "Warning", workloadInstance, apicommon.PhaseStateFailed, "has failed since app has failed", workloadInstance.GetVersion()) + r.EventSender.SendEvent(phase, "Warning", workloadInstance, apicommon.PhaseStateFailed, "has failed since app has failed", workloadInstance.GetVersion()) } } @@ -260,11 +261,11 @@ func (r *KeptnWorkloadInstanceReconciler) checkPreEvaluationStatusOfApp(ctx cont found, appVersion, err := r.getAppVersionForWorkloadInstance(ctx, workloadInstance) if err != nil { span.SetStatus(codes.Error, err.Error()) - r.EventSender.SendK8sEvent(phase, "Warning", workloadInstance, "GetAppVersionFailed", "has failed since app could not be retrieved", workloadInstance.GetVersion()) + r.EventSender.SendEvent(phase, "Warning", workloadInstance, "GetAppVersionFailed", "has failed since app could not be retrieved", workloadInstance.GetVersion()) return true, fmt.Errorf(controllererrors.ErrCannotFetchAppVersionForWorkloadInstanceMsg + err.Error()) } else if !found { span.SetStatus(codes.Error, "app could not be found") - r.EventSender.SendK8sEvent(phase, "Warning", workloadInstance, "AppVersionNotFound", "has failed since app could not be found", workloadInstance.GetVersion()) + r.EventSender.SendEvent(phase, "Warning", workloadInstance, "AppVersionNotFound", "has failed since app could not be found", workloadInstance.GetVersion()) return true, fmt.Errorf(controllererrors.ErrCannotFetchAppVersionForWorkloadInstanceMsg) } @@ -314,7 +315,7 @@ func (r *KeptnWorkloadInstanceReconciler) getAppVersionForWorkloadInstance(ctx c return true, latestVersion, nil } -func (r *KeptnWorkloadInstanceReconciler) getTracer() controllercommon.ITracer { +func (r *KeptnWorkloadInstanceReconciler) getTracer() telemetry.ITracer { return r.TracerFactory.GetTracer(traceComponentName) } diff --git a/lifecycle-operator/controllers/options/keptnconfig_controller.go b/lifecycle-operator/controllers/options/keptnconfig_controller.go index 55ec7d459b..fac1677e06 100644 --- a/lifecycle-operator/controllers/options/keptnconfig_controller.go +++ b/lifecycle-operator/controllers/options/keptnconfig_controller.go @@ -20,11 +20,11 @@ import ( "context" "fmt" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/config" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "time" "github.com/go-logr/logr" optionsv1alpha1 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/options/v1alpha1" - controllercommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" @@ -78,7 +78,7 @@ func (r *KeptnConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) func (r *KeptnConfigReconciler) reconcileOtelCollectorUrl(config *optionsv1alpha1.KeptnConfig) (ctrl.Result, error) { r.Log.Info(fmt.Sprintf("reconciling Keptn Config: %s", config.Name)) - otelConfig := controllercommon.GetOtelInstance() + otelConfig := telemetry.GetOtelInstance() if err := otelConfig.InitOtelCollector(config.Spec.OTelCollectorUrl); err != nil { r.Log.Error(err, "unable to initialize OTel tracer options") diff --git a/lifecycle-operator/main.go b/lifecycle-operator/main.go index 14c382fb3d..214bf03d11 100644 --- a/lifecycle-operator/main.go +++ b/lifecycle-operator/main.go @@ -19,6 +19,7 @@ package main import ( "flag" "fmt" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "log" "net/http" "os" @@ -115,7 +116,7 @@ func main() { } provider := metric.NewMeterProvider(metric.WithReader(exporter)) meter := provider.Meter("keptn/task") - keptnMeters := controllercommon.SetUpKeptnTaskMeters(meter) + keptnMeters := telemetry.SetUpKeptnTaskMeters(meter) // Start the prometheus HTTP server and pass the exporter Collector to it go serveMetrics() @@ -164,12 +165,12 @@ func main() { } // Enabling OTel - err = controllercommon.GetOtelInstance().InitOtelCollector("") + err = telemetry.GetOtelInstance().InitOtelCollector("") if err != nil { setupLog.Error(err, "unable to initialize OTel tracer options") } - spanHandler := &controllercommon.SpanHandler{} + spanHandler := &telemetry.SpanHandler{} taskLogger := ctrl.Log.WithName("KeptnTask Controller") taskReconciler := &keptntask.KeptnTaskReconciler{ @@ -178,7 +179,7 @@ func main() { Log: taskLogger.V(env.KeptnTaskControllerLogLevel), EventSender: controllercommon.NewEventSender(mgr.GetEventRecorderFor("keptntask-controller")), Meters: keptnMeters, - TracerFactory: controllercommon.GetOtelInstance(), + TracerFactory: telemetry.GetOtelInstance(), } if err = (taskReconciler).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KeptnTask") @@ -203,7 +204,7 @@ func main() { Scheme: mgr.GetScheme(), Log: appLogger.V(env.KeptnAppControllerLogLevel), EventSender: controllercommon.NewEventSender(mgr.GetEventRecorderFor("keptnapp-controller")), - TracerFactory: controllercommon.GetOtelInstance(), + TracerFactory: telemetry.GetOtelInstance(), } if err = (appReconciler).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KeptnApp") @@ -227,7 +228,7 @@ func main() { Scheme: mgr.GetScheme(), Log: workloadLogger.V(env.KeptnWorkloadControllerLogLevel), EventSender: controllercommon.NewEventSender(mgr.GetEventRecorderFor("keptnworkload-controller")), - TracerFactory: controllercommon.GetOtelInstance(), + TracerFactory: telemetry.GetOtelInstance(), } if err = (workloadReconciler).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KeptnWorkload") @@ -241,7 +242,7 @@ func main() { Log: workloadInstanceLogger.V(env.KeptnWorkloadInstanceControllerLogLevel), EventSender: controllercommon.NewEventSender(mgr.GetEventRecorderFor("keptnworkloadinstance-controller")), Meters: keptnMeters, - TracerFactory: controllercommon.GetOtelInstance(), + TracerFactory: telemetry.GetOtelInstance(), SpanHandler: spanHandler, } if err = (workloadInstanceReconciler).SetupWithManager(mgr); err != nil { @@ -255,7 +256,7 @@ func main() { Scheme: mgr.GetScheme(), Log: appVersionLogger.V(env.KeptnAppVersionControllerLogLevel), EventSender: controllercommon.NewEventSender(mgr.GetEventRecorderFor("keptnappversion-controller")), - TracerFactory: controllercommon.GetOtelInstance(), + TracerFactory: telemetry.GetOtelInstance(), Meters: keptnMeters, SpanHandler: spanHandler, } @@ -270,7 +271,7 @@ func main() { Scheme: mgr.GetScheme(), Log: evaluationLogger.V(env.KeptnEvaluationControllerLogLevel), EventSender: controllercommon.NewEventSender(mgr.GetEventRecorderFor("keptnevaluation-controller")), - TracerFactory: controllercommon.GetOtelInstance(), + TracerFactory: telemetry.GetOtelInstance(), Meters: keptnMeters, Namespace: env.PodNamespace, } @@ -313,7 +314,7 @@ func main() { } // +kubebuilder:scaffold:builder - controllercommon.SetUpKeptnMeters(meter, mgr.GetClient()) + telemetry.SetUpKeptnMeters(meter, mgr.GetClient()) if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { setupLog.Error(err, "unable to set up health check") diff --git a/lifecycle-operator/webhooks/pod_mutator/pod_mutating_webhook.go b/lifecycle-operator/webhooks/pod_mutator/pod_mutating_webhook.go index d930f74247..2f96390dfe 100644 --- a/lifecycle-operator/webhooks/pod_mutator/pod_mutating_webhook.go +++ b/lifecycle-operator/webhooks/pod_mutator/pod_mutating_webhook.go @@ -39,7 +39,7 @@ type PodMutatingWebhook struct { Client client.Client Tracer trace.Tracer Decoder *admission.Decoder - EventSender controllercommon.EventSender + EventSender controllercommon.IEvent Log logr.Logger } @@ -288,7 +288,7 @@ func (a *PodMutatingWebhook) handleWorkload(ctx context.Context, logger logr.Log err = a.Client.Create(ctx, workload) if err != nil { logger.Error(err, "Could not create Workload") - a.EventSender.SendK8sEvent(apicommon.PhaseCreateWorkload, "Warning", workload, apicommon.PhaseStateFailed, "could not create KeptnWorkload", workload.Spec.Version) + a.EventSender.SendEvent(apicommon.PhaseCreateWorkload, "Warning", workload, apicommon.PhaseStateFailed, "could not create KeptnWorkload", workload.Spec.Version) span.SetStatus(codes.Error, err.Error()) return err } @@ -312,7 +312,7 @@ func (a *PodMutatingWebhook) handleWorkload(ctx context.Context, logger logr.Log err = a.Client.Update(ctx, workload) if err != nil { logger.Error(err, "Could not update Workload") - a.EventSender.SendK8sEvent(apicommon.PhaseUpdateWorkload, "Warning", workload, apicommon.PhaseStateFailed, "could not update KeptnWorkload", workload.Spec.Version) + a.EventSender.SendEvent(apicommon.PhaseUpdateWorkload, "Warning", workload, apicommon.PhaseStateFailed, "could not update KeptnWorkload", workload.Spec.Version) span.SetStatus(codes.Error, err.Error()) return err } @@ -340,7 +340,7 @@ func (a *PodMutatingWebhook) handleApp(ctx context.Context, logger logr.Logger, err = a.Client.Create(ctx, appCreationRequest) if err != nil { logger.Error(err, "Could not create AppCreationRequest") - a.EventSender.SendK8sEvent(apicommon.PhaseCreateAppCreationRequest, "Warning", appCreationRequest, apicommon.PhaseStateFailed, "could not create KeptnAppCreationRequest", appCreationRequest.Spec.AppName) + a.EventSender.SendEvent(apicommon.PhaseCreateAppCreationRequest, "Warning", appCreationRequest, apicommon.PhaseStateFailed, "could not create KeptnAppCreationRequest", appCreationRequest.Spec.AppName) span.SetStatus(codes.Error, err.Error()) return err } From fad50bd0a053b39a9a1bf984a54ed6e8aa730583 Mon Sep 17 00:00:00 2001 From: Giovanni Liva Date: Sun, 6 Aug 2023 17:44:45 +0200 Subject: [PATCH 3/5] fix tests Signed-off-by: Giovanni Liva --- .../lifecycle/keptnevaluation/controller_test.go | 3 ++- .../keptnworkloadinstance/controller_test.go | 3 ++- .../component/appversion/appversion_suite_test.go | 3 ++- lifecycle-operator/test/component/common/common.go | 4 ++-- .../workloadinstance_suite_test.go | 3 ++- .../pod_mutator/pod_mutating_webhook_test.go | 14 +++++++------- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller_test.go b/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller_test.go index c218d50f4f..c17e6c0482 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller_test.go +++ b/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller_test.go @@ -10,6 +10,7 @@ import ( "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" controllercommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/fake" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" metricsapi "github.com/keptn/lifecycle-toolkit/lifecycle-operator/test/api/metrics/v1alpha3" "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/sdk/metric" @@ -260,7 +261,7 @@ func setupReconcilerAndClient(t *testing.T, objects ...client.Object) (*KeptnEva Scheme: fakeClient.Scheme(), Log: logr.Logger{}, EventSender: controllercommon.NewEventSender(record.NewFakeRecorder(100)), - Meters: controllercommon.SetUpKeptnTaskMeters(meter), + Meters: telemetry.SetUpKeptnTaskMeters(meter), TracerFactory: tf, } return r, fakeClient diff --git a/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller_test.go b/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller_test.go index a27618a70e..d5f10c2a86 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller_test.go +++ b/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller_test.go @@ -11,6 +11,7 @@ import ( apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" controllercommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/fake" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors" "github.com/magiconair/properties/assert" "github.com/stretchr/testify/require" @@ -1067,7 +1068,7 @@ func setupReconciler() (*KeptnWorkloadInstanceReconciler, chan string, *fake.ITr Log: ctrl.Log.WithName("test-appController"), TracerFactory: tf, Meters: controllercommon.InitAppMeters(), - SpanHandler: &controllercommon.SpanHandler{}, + SpanHandler: &telemetry.SpanHandler{}, } return r, recorder.Events, tr } diff --git a/lifecycle-operator/test/component/appversion/appversion_suite_test.go b/lifecycle-operator/test/component/appversion/appversion_suite_test.go index b6e692858f..08a389e7aa 100644 --- a/lifecycle-operator/test/component/appversion/appversion_suite_test.go +++ b/lifecycle-operator/test/component/appversion/appversion_suite_test.go @@ -7,6 +7,7 @@ import ( "time" controllercommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/lifecycle/keptnappversion" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/test/component/common" . "github.com/onsi/ginkgo/v2" @@ -43,7 +44,7 @@ var _ = BeforeSuite(func() { EventSender: controllercommon.NewEventSender(k8sManager.GetEventRecorderFor("test-appversion-controller")), Log: GinkgoLogr, Meters: common.InitKeptnMeters(), - SpanHandler: &controllercommon.SpanHandler{}, + SpanHandler: &telemetry.SpanHandler{}, TracerFactory: &common.TracerFactory{Tracer: tracer}, } Eventually(controller.SetupWithManager(k8sManager)).WithTimeout(30 * time.Second).WithPolling(time.Second).Should(Succeed()) diff --git a/lifecycle-operator/test/component/common/common.go b/lifecycle-operator/test/component/common/common.go index ca2695ce79..2c1065ad7d 100644 --- a/lifecycle-operator/test/component/common/common.go +++ b/lifecycle-operator/test/component/common/common.go @@ -3,6 +3,7 @@ package common import ( "context" "fmt" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "os" "path/filepath" "strings" @@ -10,7 +11,6 @@ import ( klcv1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" - controllercommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" metricsapi "github.com/keptn/lifecycle-toolkit/lifecycle-operator/test/api/metrics/v1alpha3" . "github.com/onsi/ginkgo/v2" ginkgotypes "github.com/onsi/ginkgo/v2/types" @@ -63,7 +63,7 @@ type TracerFactory struct { Tracer trace.TracerProvider } -func (f *TracerFactory) GetTracer(name string) controllercommon.ITracer { +func (f *TracerFactory) GetTracer(name string) telemetry.ITracer { return f.Tracer.Tracer(name) } diff --git a/lifecycle-operator/test/component/workloadinstance/workloadinstance_suite_test.go b/lifecycle-operator/test/component/workloadinstance/workloadinstance_suite_test.go index 831c1af650..446fa3b491 100644 --- a/lifecycle-operator/test/component/workloadinstance/workloadinstance_suite_test.go +++ b/lifecycle-operator/test/component/workloadinstance/workloadinstance_suite_test.go @@ -7,6 +7,7 @@ import ( "time" controllercommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/test/component/common" . "github.com/onsi/ginkgo/v2" @@ -43,7 +44,7 @@ var _ = BeforeSuite(func() { EventSender: controllercommon.NewEventSender(k8sManager.GetEventRecorderFor("test-workloadinstance-controller")), Log: GinkgoLogr, Meters: common.InitKeptnMeters(), - SpanHandler: &controllercommon.SpanHandler{}, + SpanHandler: &telemetry.SpanHandler{}, TracerFactory: &common.TracerFactory{Tracer: tracer}, } Eventually(controller.SetupWithManager(k8sManager)).WithTimeout(30 * time.Second).WithPolling(time.Second).Should(Succeed()) diff --git a/lifecycle-operator/webhooks/pod_mutator/pod_mutating_webhook_test.go b/lifecycle-operator/webhooks/pod_mutator/pod_mutating_webhook_test.go index d4f3579531..1fb0c46d06 100644 --- a/lifecycle-operator/webhooks/pod_mutator/pod_mutating_webhook_test.go +++ b/lifecycle-operator/webhooks/pod_mutator/pod_mutating_webhook_test.go @@ -31,7 +31,7 @@ func TestPodMutatingWebhook_getOwnerReference(t *testing.T) { Client client.Client Tracer trace.Tracer Decoder *admission.Decoder - EventSender controllercommon.EventSender + EventSender controllercommon.IEvent Log logr.Logger } type args struct { @@ -104,7 +104,7 @@ func TestPodMutatingWebhook_getAppName(t *testing.T) { Client client.Client Tracer trace.Tracer Decoder *admission.Decoder - EventSender controllercommon.EventSender + EventSender controllercommon.IEvent Log logr.Logger } type args struct { @@ -180,7 +180,7 @@ func TestPodMutatingWebhook_getWorkloadName(t *testing.T) { Client client.Client Tracer trace.Tracer Decoder *admission.Decoder - EventSender controllercommon.EventSender + EventSender controllercommon.IEvent Log logr.Logger } type args struct { @@ -370,7 +370,7 @@ func TestPodMutatingWebhook_isPodAnnotated(t *testing.T) { Client client.Client Tracer trace.Tracer Decoder *admission.Decoder - EventSender controllercommon.EventSender + EventSender controllercommon.IEvent Log logr.Logger } type args struct { @@ -541,7 +541,7 @@ func TestPodMutatingWebhook_copyAnnotationsIfParentAnnotated(t *testing.T) { Client client.Client Tracer trace.Tracer Decoder *admission.Decoder - EventSender controllercommon.EventSender + EventSender controllercommon.IEvent Log logr.Logger } type args struct { @@ -711,7 +711,7 @@ func TestPodMutatingWebhook_copyResourceLabelsIfPresent(t *testing.T) { Client client.Client Tracer trace.Tracer Decoder *admission.Decoder - EventSender controllercommon.EventSender + EventSender controllercommon.IEvent Log logr.Logger } type args struct { @@ -873,7 +873,7 @@ func TestPodMutatingWebhook_isAppAnnotationPresent(t *testing.T) { Client client.Client Tracer trace.Tracer Decoder *admission.Decoder - EventSender controllercommon.EventSender + EventSender controllercommon.IEvent Log logr.Logger } type args struct { From 6eda5d4d9528153e855006a03cc1bdd6068f76c2 Mon Sep 17 00:00:00 2001 From: Giovanni Liva Date: Sun, 6 Aug 2023 18:12:02 +0200 Subject: [PATCH 4/5] gci import Signed-off-by: Giovanni Liva --- lifecycle-operator/controllers/common/eventsender.go | 1 + .../controllers/lifecycle/keptnapp/controller.go | 2 +- .../controllers/lifecycle/keptnappversion/controller.go | 2 +- .../controllers/lifecycle/keptnevaluation/controller.go | 2 +- .../controllers/lifecycle/keptntask/controller.go | 2 +- .../controllers/lifecycle/keptnworkload/controller.go | 2 +- .../controllers/lifecycle/keptnworkloadinstance/controller.go | 2 +- .../controllers/options/keptnconfig_controller.go | 4 ++-- lifecycle-operator/main.go | 2 +- lifecycle-operator/test/component/common/common.go | 2 +- 10 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lifecycle-operator/controllers/common/eventsender.go b/lifecycle-operator/controllers/common/eventsender.go index 2b7edb1b1a..8e7f6ec9b2 100644 --- a/lifecycle-operator/controllers/common/eventsender.go +++ b/lifecycle-operator/controllers/common/eventsender.go @@ -2,6 +2,7 @@ package common import ( "fmt" + apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go b/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go index 6b7227a62a..6b75570dbf 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go @@ -19,13 +19,13 @@ package keptnapp import ( "context" "fmt" - "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "github.com/go-logr/logr" klcv1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" operatorcommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/common" controllercommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/codes" diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go index 19e8446246..4b49bb0e4c 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go @@ -19,13 +19,13 @@ package keptnappversion import ( "context" "fmt" - "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "time" "github.com/go-logr/logr" klcv1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" controllercommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/codes" diff --git a/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller.go b/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller.go index 9b51f8b76d..140af8b358 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller.go @@ -19,7 +19,6 @@ package keptnevaluation import ( "context" "fmt" - "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "time" "github.com/go-logr/logr" @@ -27,6 +26,7 @@ import ( apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" controllercommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/providers/keptnmetric" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/codes" diff --git a/lifecycle-operator/controllers/lifecycle/keptntask/controller.go b/lifecycle-operator/controllers/lifecycle/keptntask/controller.go index 7768a764da..caf524a57c 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntask/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptntask/controller.go @@ -18,13 +18,13 @@ package keptntask import ( "context" - "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "time" "github.com/go-logr/logr" klcv1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" controllercommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/metric" diff --git a/lifecycle-operator/controllers/lifecycle/keptnworkload/controller.go b/lifecycle-operator/controllers/lifecycle/keptnworkload/controller.go index 80619df6dc..ac7c927c00 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnworkload/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnworkload/controller.go @@ -19,12 +19,12 @@ package keptnworkload import ( "context" "fmt" - "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "github.com/go-logr/logr" klcv1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" controllercommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/codes" diff --git a/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller.go b/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller.go index ff92590572..01d4989ecd 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller.go @@ -19,13 +19,13 @@ package keptnworkloadinstance import ( "context" "fmt" - "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "time" "github.com/go-logr/logr" klcv1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" controllercommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/codes" diff --git a/lifecycle-operator/controllers/options/keptnconfig_controller.go b/lifecycle-operator/controllers/options/keptnconfig_controller.go index fac1677e06..b0a97ed80a 100644 --- a/lifecycle-operator/controllers/options/keptnconfig_controller.go +++ b/lifecycle-operator/controllers/options/keptnconfig_controller.go @@ -19,12 +19,12 @@ package options import ( "context" "fmt" - "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/config" - "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "time" "github.com/go-logr/logr" 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/telemetry" controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" diff --git a/lifecycle-operator/main.go b/lifecycle-operator/main.go index 214bf03d11..72943d3fcc 100644 --- a/lifecycle-operator/main.go +++ b/lifecycle-operator/main.go @@ -19,7 +19,6 @@ package main import ( "flag" "fmt" - "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "log" "net/http" "os" @@ -34,6 +33,7 @@ import ( lifecyclev1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" optionsv1alpha1 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/options/v1alpha1" controllercommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/lifecycle/keptnapp" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/lifecycle/keptnappcreationrequest" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/lifecycle/keptnappversion" diff --git a/lifecycle-operator/test/component/common/common.go b/lifecycle-operator/test/component/common/common.go index 2c1065ad7d..3f82e8abad 100644 --- a/lifecycle-operator/test/component/common/common.go +++ b/lifecycle-operator/test/component/common/common.go @@ -3,7 +3,6 @@ package common import ( "context" "fmt" - "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" "os" "path/filepath" "strings" @@ -11,6 +10,7 @@ import ( klcv1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" metricsapi "github.com/keptn/lifecycle-toolkit/lifecycle-operator/test/api/metrics/v1alpha3" . "github.com/onsi/ginkgo/v2" ginkgotypes "github.com/onsi/ginkgo/v2/types" From 376b59fe10a7e5cff15a7ec4b2d7dbf580660876 Mon Sep 17 00:00:00 2001 From: Giovanni Liva Date: Mon, 7 Aug 2023 11:34:58 +0200 Subject: [PATCH 5/5] change naming of function Signed-off-by: Giovanni Liva --- .../controllers/common/evaluationhandler.go | 6 +++--- lifecycle-operator/controllers/common/eventsender.go | 4 ++-- lifecycle-operator/controllers/common/eventsender_test.go | 2 +- lifecycle-operator/controllers/common/phasehandler.go | 8 ++++---- lifecycle-operator/controllers/common/taskhandler.go | 4 ++-- .../controllers/lifecycle/keptnapp/controller.go | 4 ++-- .../controllers/lifecycle/keptnappversion/controller.go | 2 +- .../lifecycle/keptnappversion/reconcile_workloadsstate.go | 2 +- .../controllers/lifecycle/keptnevaluation/controller.go | 6 +++--- .../controllers/lifecycle/keptntask/job_utils.go | 4 ++-- .../controllers/lifecycle/keptntask/runtime_builder.go | 6 +++--- .../lifecycle/keptntaskdefinition/reconcile_function.go | 4 ++-- .../controllers/lifecycle/keptnworkload/controller.go | 2 +- .../lifecycle/keptnworkloadinstance/controller.go | 8 ++++---- .../webhooks/pod_mutator/pod_mutating_webhook.go | 6 +++--- 15 files changed, 34 insertions(+), 34 deletions(-) diff --git a/lifecycle-operator/controllers/common/evaluationhandler.go b/lifecycle-operator/controllers/common/evaluationhandler.go index 4f993e406e..fa264546c8 100644 --- a/lifecycle-operator/controllers/common/evaluationhandler.go +++ b/lifecycle-operator/controllers/common/evaluationhandler.go @@ -56,7 +56,7 @@ func (r EvaluationHandler) ReconcileEvaluations(ctx context.Context, phaseCtx co evaluationExists := false if oldstatus != evaluationStatus.Status { - r.EventSender.SendEvent(apicommon.PhaseReconcileEvaluation, "Normal", reconcileObject, apicommon.PhaseStateStatusChanged, fmt.Sprintf("evaluation status changed from %s to %s", oldstatus, evaluationStatus.Status), piWrapper.GetVersion()) + r.EventSender.Emit(apicommon.PhaseReconcileEvaluation, "Normal", reconcileObject, apicommon.PhaseStateStatusChanged, fmt.Sprintf("evaluation status changed from %s to %s", oldstatus, evaluationStatus.Status), piWrapper.GetVersion()) } // Check if evaluation has already succeeded or failed @@ -127,7 +127,7 @@ func (r EvaluationHandler) CreateKeptnEvaluation(ctx context.Context, namespace err = r.Client.Create(ctx, &newEvaluation) if err != nil { r.Log.Error(err, "could not create KeptnEvaluation") - r.EventSender.SendEvent(phase, "Warning", reconcileObject, apicommon.PhaseStateFailed, "could not create KeptnEvaluation", piWrapper.GetVersion()) + r.EventSender.Emit(phase, "Warning", reconcileObject, apicommon.PhaseStateFailed, "could not create KeptnEvaluation", piWrapper.GetVersion()) return "", err } @@ -143,7 +143,7 @@ func (r EvaluationHandler) emitEvaluationFailureEvents(evaluation *klcv1alpha3.K k8sEventMessage = fmt.Sprintf("%s\n%s", k8sEventMessage, msg) } } - r.EventSender.SendEvent(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateFailed, k8sEventMessage, piWrapper.GetVersion()) + r.EventSender.Emit(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateFailed, k8sEventMessage, piWrapper.GetVersion()) } func (r EvaluationHandler) setupEvaluations(evaluationCreateAttributes CreateEvaluationAttributes, piWrapper *interfaces.PhaseItemWrapper) ([]string, []klcv1alpha3.ItemStatus) { diff --git a/lifecycle-operator/controllers/common/eventsender.go b/lifecycle-operator/controllers/common/eventsender.go index 8e7f6ec9b2..b9fa76b5f5 100644 --- a/lifecycle-operator/controllers/common/eventsender.go +++ b/lifecycle-operator/controllers/common/eventsender.go @@ -10,7 +10,7 @@ import ( //go:generate moq -pkg fake -skip-ensure -out ./fake/event_mock.go . IEvent:MockEvent type IEvent interface { - SendEvent(phase apicommon.KeptnPhaseType, eventType string, reconcileObject client.Object, status string, message string, version string) + Emit(phase apicommon.KeptnPhaseType, eventType string, reconcileObject client.Object, status string, message string, version string) } // ===== Main ===== @@ -35,7 +35,7 @@ func newK8sSender(recorder record.EventRecorder) IEvent { } // SendEvent creates k8s Event and adds it to Eventqueue -func (s *k8sEvent) SendEvent(phase apicommon.KeptnPhaseType, eventType string, reconcileObject client.Object, status string, message string, version string) { +func (s *k8sEvent) Emit(phase apicommon.KeptnPhaseType, eventType string, reconcileObject client.Object, status string, message string, version string) { msg := setEventMessage(phase, reconcileObject, message, version) annotations := setAnnotations(reconcileObject, phase) s.recorder.AnnotatedEventf(reconcileObject, annotations, eventType, fmt.Sprintf("%s%s", phase.ShortName, status), msg) diff --git a/lifecycle-operator/controllers/common/eventsender_test.go b/lifecycle-operator/controllers/common/eventsender_test.go index c1b5241fc0..2b8285ea29 100644 --- a/lifecycle-operator/controllers/common/eventsender_test.go +++ b/lifecycle-operator/controllers/common/eventsender_test.go @@ -15,7 +15,7 @@ func TestEventSender_SendK8sEvent(t *testing.T) { fakeRecorder := record.NewFakeRecorder(100) eventSender := newK8sSender(fakeRecorder) - eventSender.SendEvent(common.PhaseAppDeployment, "pre-event", &v1alpha3.KeptnAppVersion{ + eventSender.Emit(common.PhaseAppDeployment, "pre-event", &v1alpha3.KeptnAppVersion{ ObjectMeta: v1.ObjectMeta{ Name: "app", Namespace: "ns", diff --git a/lifecycle-operator/controllers/common/phasehandler.go b/lifecycle-operator/controllers/common/phasehandler.go index 4327897ee3..3ca5ce5c46 100644 --- a/lifecycle-operator/controllers/common/phasehandler.go +++ b/lifecycle-operator/controllers/common/phasehandler.go @@ -40,7 +40,7 @@ func (r PhaseHandler) HandlePhase(ctx context.Context, ctxTrace context.Context, return &PhaseResult{Continue: false, Result: ctrl.Result{}}, nil } if oldPhase != phase.ShortName { - r.EventSender.SendEvent(phase, "Normal", reconcileObject, apicommon.PhaseStateStarted, "has started", piWrapper.GetVersion()) + r.EventSender.Emit(phase, "Normal", reconcileObject, apicommon.PhaseStateStarted, "has started", piWrapper.GetVersion()) piWrapper.SetCurrentPhase(phase.ShortName) } @@ -52,7 +52,7 @@ func (r PhaseHandler) HandlePhase(ctx context.Context, ctxTrace context.Context, state, err := reconcilePhase(spanPhaseCtx) if err != nil { spanPhaseTrace.AddEvent(phase.LongName + " could not get reconciled") - r.EventSender.SendEvent(phase, "Warning", reconcileObject, apicommon.PhaseStateReconcileError, "could not get reconciled", piWrapper.GetVersion()) + r.EventSender.Emit(phase, "Warning", reconcileObject, apicommon.PhaseStateReconcileError, "could not get reconciled", piWrapper.GetVersion()) span.SetStatus(codes.Error, err.Error()) return &PhaseResult{Continue: false, Result: requeueResult}, err } @@ -89,7 +89,7 @@ func (r PhaseHandler) handleCompletedPhase(state apicommon.KeptnState, piWrapper if err := r.SpanHandler.UnbindSpan(reconcileObject, phase.ShortName); err != nil { r.Log.Error(err, controllererrors.ErrCouldNotUnbindSpan, reconcileObject.GetName()) } - r.EventSender.SendEvent(phase, "Warning", reconcileObject, apicommon.PhaseStateFailed, "has failed", piWrapper.GetVersion()) + r.EventSender.Emit(phase, "Warning", reconcileObject, apicommon.PhaseStateFailed, "has failed", piWrapper.GetVersion()) piWrapper.DeprecateRemainingPhases(phase) return &PhaseResult{Continue: false, Result: ctrl.Result{}}, nil } @@ -101,7 +101,7 @@ func (r PhaseHandler) handleCompletedPhase(state apicommon.KeptnState, piWrapper if err := r.SpanHandler.UnbindSpan(reconcileObject, phase.ShortName); err != nil { r.Log.Error(err, controllererrors.ErrCouldNotUnbindSpan, reconcileObject.GetName()) } - r.EventSender.SendEvent(phase, "Normal", reconcileObject, apicommon.PhaseStateFinished, "has finished", piWrapper.GetVersion()) + r.EventSender.Emit(phase, "Normal", reconcileObject, apicommon.PhaseStateFinished, "has finished", piWrapper.GetVersion()) return &PhaseResult{Continue: true, Result: ctrl.Result{Requeue: true, RequeueAfter: 5 * time.Second}}, nil } diff --git a/lifecycle-operator/controllers/common/taskhandler.go b/lifecycle-operator/controllers/common/taskhandler.go index 54c010ef58..63da8745af 100644 --- a/lifecycle-operator/controllers/common/taskhandler.go +++ b/lifecycle-operator/controllers/common/taskhandler.go @@ -58,7 +58,7 @@ func (r TaskHandler) ReconcileTasks(ctx context.Context, phaseCtx context.Contex taskExists := false if oldstatus != taskStatus.Status { - r.EventSender.SendEvent(phase, "Normal", reconcileObject, apicommon.PhaseStateStatusChanged, fmt.Sprintf("task status changed from %s to %s", oldstatus, taskStatus.Status), piWrapper.GetVersion()) + r.EventSender.Emit(phase, "Normal", reconcileObject, apicommon.PhaseStateStatusChanged, fmt.Sprintf("task status changed from %s to %s", oldstatus, taskStatus.Status), piWrapper.GetVersion()) } // Check if task has already succeeded or failed @@ -131,7 +131,7 @@ func (r TaskHandler) CreateKeptnTask(ctx context.Context, namespace string, reco err = r.Client.Create(ctx, &newTask) if err != nil { r.Log.Error(err, "could not create KeptnTask") - r.EventSender.SendEvent(phase, "Warning", reconcileObject, apicommon.PhaseStateFailed, "could not create KeptnTask", piWrapper.GetVersion()) + r.EventSender.Emit(phase, "Warning", reconcileObject, apicommon.PhaseStateFailed, "could not create KeptnTask", piWrapper.GetVersion()) return "", err } diff --git a/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go b/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go index 6b75570dbf..f38a7a3a27 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go @@ -106,7 +106,7 @@ func (r *KeptnAppReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c if err != nil { r.Log.Error(err, "could not create AppVersion") span.SetStatus(codes.Error, err.Error()) - r.EventSender.SendEvent(common.PhaseCreateAppVersion, "Warning", appVersion, common.PhaseStateFailed, "Could not create KeptnAppVersion", appVersion.Spec.Version) + r.EventSender.Emit(common.PhaseCreateAppVersion, "Warning", appVersion, common.PhaseStateFailed, "Could not create KeptnAppVersion", appVersion.Spec.Version) return ctrl.Result{}, err } @@ -172,7 +172,7 @@ func (r *KeptnAppReconciler) handleGenerationBump(ctx context.Context, app *klcv if app.Generation != 1 { if err := r.deprecateAppVersions(ctx, app); err != nil { r.Log.Error(err, "could not deprecate appVersions for appVersion %s", app.GetAppVersionName()) - r.EventSender.SendEvent(common.PhaseDeprecateAppVersion, "Warning", app, common.PhaseStateFailed, fmt.Sprintf("could not deprecate outdated revisions of KeptnAppVersion: %s", app.GetAppVersionName()), app.Spec.Version) + r.EventSender.Emit(common.PhaseDeprecateAppVersion, "Warning", app, common.PhaseStateFailed, fmt.Sprintf("could not deprecate outdated revisions of KeptnAppVersion: %s", app.GetAppVersionName()), app.Spec.Version) return err } } diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go index 4b49bb0e4c..f6e8bf063e 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go @@ -182,7 +182,7 @@ func (r *KeptnAppVersionReconciler) finishKeptnAppVersionReconcile(ctx context.C return ctrl.Result{Requeue: true}, err } - r.EventSender.SendEvent(apicommon.PhaseAppCompleted, "Normal", appVersion, apicommon.PhaseStateFinished, "has finished", appVersion.GetVersion()) + r.EventSender.Emit(apicommon.PhaseAppCompleted, "Normal", appVersion, apicommon.PhaseStateFinished, "has finished", appVersion.GetVersion()) attrs := appVersion.GetMetricsAttributes() diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_workloadsstate.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_workloadsstate.go index 09297e6f7f..9ac81a6c46 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_workloadsstate.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/reconcile_workloadsstate.go @@ -41,7 +41,7 @@ func (r *KeptnAppVersionReconciler) reconcileWorkloads(ctx context.Context, appV } if !found { - r.EventSender.SendEvent(phase, "Warning", appVersion, apicommon.PhaseStateNotFound, fmt.Sprintf("could not find KeptnWorkloadInstance for KeptnWorkload: %s ", w.Name), appVersion.GetVersion()) + r.EventSender.Emit(phase, "Warning", appVersion, apicommon.PhaseStateNotFound, fmt.Sprintf("could not find KeptnWorkloadInstance for KeptnWorkload: %s ", w.Name), appVersion.GetVersion()) } newStatus = append(newStatus, klcv1alpha3.WorkloadStatus{ diff --git a/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller.go b/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller.go index 140af8b358..44423c7179 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller.go @@ -139,7 +139,7 @@ func (r *KeptnEvaluationReconciler) handleEvaluationIncomplete(ctx context.Conte // Evaluation is uncompleted, update status anyway this avoids updating twice in case of completion err := r.Client.Status().Update(ctx, evaluation) if err != nil { - r.EventSender.SendEvent(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateReconcileError, "could not update status", "") + r.EventSender.Emit(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateReconcileError, "could not update status", "") span.SetStatus(codes.Error, err.Error()) return err } @@ -149,7 +149,7 @@ func (r *KeptnEvaluationReconciler) handleEvaluationIncomplete(ctx context.Conte } func (r *KeptnEvaluationReconciler) handleEvaluationExceededRetries(ctx context.Context, evaluation *klcv1alpha3.KeptnEvaluation, span trace.Span) { - r.EventSender.SendEvent(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateReconcileTimeout, "retryCount exceeded", "") + r.EventSender.Emit(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateReconcileTimeout, "retryCount exceeded", "") err := controllererrors.ErrRetryCountExceeded span.SetStatus(codes.Error, err.Error()) evaluation.Status.OverallStatus = apicommon.StateFailed @@ -238,7 +238,7 @@ func (r *KeptnEvaluationReconciler) updateFinishedEvaluationMetrics(ctx context. err := r.Client.Status().Update(ctx, evaluation) if err != nil { span.SetStatus(codes.Error, err.Error()) - r.EventSender.SendEvent(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateReconcileError, "could not update status", "") + r.EventSender.Emit(apicommon.PhaseReconcileEvaluation, "Warning", evaluation, apicommon.PhaseStateReconcileError, "could not update status", "") return err } diff --git a/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go b/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go index 22290dfba7..d336171c91 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go +++ b/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go @@ -21,7 +21,7 @@ func (r *KeptnTaskReconciler) createJob(ctx context.Context, req ctrl.Request, t definition, err := controllercommon.GetTaskDefinition(r.Client, r.Log, ctx, task.Spec.TaskDefinition, req.Namespace) if err != nil { r.Log.Error(err, fmt.Sprintf("could not find KeptnTaskDefinition: %s ", task.Spec.TaskDefinition)) - r.EventSender.SendEvent(apicommon.PhaseCreateTask, "Warning", task, apicommon.PhaseStateNotFound, fmt.Sprintf("could not find KeptnTaskDefinition: %s ", task.Spec.TaskDefinition), "") + r.EventSender.Emit(apicommon.PhaseCreateTask, "Warning", task, apicommon.PhaseStateNotFound, fmt.Sprintf("could not find KeptnTaskDefinition: %s ", task.Spec.TaskDefinition), "") return err } @@ -47,7 +47,7 @@ func (r *KeptnTaskReconciler) createFunctionJob(ctx context.Context, req ctrl.Re err = r.Client.Create(ctx, job) if err != nil { r.Log.Error(err, "could not create Job") - r.EventSender.SendEvent(apicommon.PhaseCreateTask, "Warning", task, apicommon.PhaseStateFailed, fmt.Sprintf("could not create Job: %s ", task.Name), "") + r.EventSender.Emit(apicommon.PhaseCreateTask, "Warning", task, apicommon.PhaseStateFailed, fmt.Sprintf("could not create Job: %s ", task.Name), "") return job.Name, err } diff --git a/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder.go b/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder.go index 9b2e7d4fdb..670b46eca2 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder.go +++ b/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder.go @@ -157,7 +157,7 @@ func (fb *RuntimeBuilder) getParams(ctx context.Context) (*RuntimeExecutionParam if len(fb.options.task.Spec.Parameters.Inline) > 0 { err = mergo.Merge(¶ms.Parameters, fb.options.task.Spec.Parameters.Inline) if err != nil { - fb.options.eventSender.SendEvent(apicommon.PhaseCreateTask, "Warning", fb.options.task, apicommon.PhaseStateFailed, fmt.Sprintf("could not merge KeptnTaskDefinition: %s ", fb.options.task.Spec.TaskDefinition), "") + fb.options.eventSender.Emit(apicommon.PhaseCreateTask, "Warning", fb.options.task, apicommon.PhaseStateFailed, fmt.Sprintf("could not merge KeptnTaskDefinition: %s ", fb.options.task.Spec.TaskDefinition), "") return nil, err } } @@ -211,7 +211,7 @@ func (fb *RuntimeBuilder) handleParent(ctx context.Context, params *RuntimeExecu var parentJobParams RuntimeExecutionParams parentDefinition, err := controllercommon.GetTaskDefinition(fb.options.Client, fb.options.Log, ctx, fb.options.funcSpec.FunctionReference.Name, fb.options.req.Namespace) if err != nil { - fb.options.eventSender.SendEvent(apicommon.PhaseCreateTask, "Warning", fb.options.task, apicommon.PhaseStateNotFound, fmt.Sprintf("could not find KeptnTaskDefinition: %s ", fb.options.task.Spec.TaskDefinition), "") + fb.options.eventSender.Emit(apicommon.PhaseCreateTask, "Warning", fb.options.task, apicommon.PhaseStateNotFound, fmt.Sprintf("could not find KeptnTaskDefinition: %s ", fb.options.task.Spec.TaskDefinition), "") return err } parSpec := controllercommon.GetRuntimeSpec(parentDefinition) @@ -223,7 +223,7 @@ func (fb *RuntimeBuilder) handleParent(ctx context.Context, params *RuntimeExecu // merge parameter to make sure we use child task data for env var and secrets err = mergo.Merge(params, parentJobParams) if err != nil { - fb.options.eventSender.SendEvent(apicommon.PhaseCreateTask, "Warning", fb.options.task, apicommon.PhaseStateFailed, fmt.Sprintf("could not merge KeptnTaskDefinition: %s ", fb.options.task.Spec.TaskDefinition), "") + fb.options.eventSender.Emit(apicommon.PhaseCreateTask, "Warning", fb.options.task, apicommon.PhaseStateFailed, fmt.Sprintf("could not merge KeptnTaskDefinition: %s ", fb.options.task.Spec.TaskDefinition), "") return err } diff --git a/lifecycle-operator/controllers/lifecycle/keptntaskdefinition/reconcile_function.go b/lifecycle-operator/controllers/lifecycle/keptntaskdefinition/reconcile_function.go index 4f1b9b9c85..1734b6c242 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntaskdefinition/reconcile_function.go +++ b/lifecycle-operator/controllers/lifecycle/keptntaskdefinition/reconcile_function.go @@ -32,14 +32,14 @@ func (r *KeptnTaskDefinitionReconciler) reconcileConfigMap(ctx context.Context, err := r.Client.Create(ctx, functionCm) if err != nil { r.Log.Error(err, "could not create ConfigMap") - r.EventSender.SendEvent(apicommon.PhaseReconcileTask, "Warning", functionCm, apicommon.PhaseStateFailed, "could not create configmap", "") + r.EventSender.Emit(apicommon.PhaseReconcileTask, "Warning", functionCm, apicommon.PhaseStateFailed, "could not create configmap", "") return } } else if !reflect.DeepEqual(cm, functionCm) && functionCm != nil { // cm and inline func exists but differ err := r.Client.Update(ctx, functionCm) if err != nil { r.Log.Error(err, "could not update ConfigMap") - r.EventSender.SendEvent(apicommon.PhaseReconcileTask, "Warning", functionCm, apicommon.PhaseStateFailed, "could not update configmap", "") + r.EventSender.Emit(apicommon.PhaseReconcileTask, "Warning", functionCm, apicommon.PhaseStateFailed, "could not update configmap", "") return } } diff --git a/lifecycle-operator/controllers/lifecycle/keptnworkload/controller.go b/lifecycle-operator/controllers/lifecycle/keptnworkload/controller.go index ac7c927c00..0cf60216ea 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnworkload/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnworkload/controller.go @@ -105,7 +105,7 @@ func (r *KeptnWorkloadReconciler) Reconcile(ctx context.Context, req ctrl.Reques if err != nil { r.Log.Error(err, "could not create WorkloadInstance") span.SetStatus(codes.Error, err.Error()) - r.EventSender.SendEvent(apicommon.PhaseCreateWorklodInstance, "Warning", workloadInstance, apicommon.PhaseStateFailed, "could not create KeptnWorkloadInstance ", workloadInstance.Spec.Version) + r.EventSender.Emit(apicommon.PhaseCreateWorklodInstance, "Warning", workloadInstance, apicommon.PhaseStateFailed, "could not create KeptnWorkloadInstance ", workloadInstance.Spec.Version) return ctrl.Result{}, err } workload.Status.CurrentVersion = workload.Spec.Version diff --git a/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller.go b/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller.go index 01d4989ecd..ee887ec721 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnworkloadinstance/controller.go @@ -191,7 +191,7 @@ func (r *KeptnWorkloadInstanceReconciler) finishKeptnWorkloadInstanceReconcile(c return ctrl.Result{Requeue: true}, err } - r.EventSender.SendEvent(apicommon.PhaseWorkloadCompleted, "Normal", workloadInstance, apicommon.PhaseStateFinished, "has finished", workloadInstance.GetVersion()) + r.EventSender.Emit(apicommon.PhaseWorkloadCompleted, "Normal", workloadInstance, apicommon.PhaseStateFinished, "has finished", workloadInstance.GetVersion()) attrs := workloadInstance.GetMetricsAttributes() @@ -225,7 +225,7 @@ func (r *KeptnWorkloadInstanceReconciler) SetupWithManager(mgr ctrl.Manager) err func (r *KeptnWorkloadInstanceReconciler) sendUnfinishedPreEvaluationEvents(appPreEvalStatus apicommon.KeptnState, phase apicommon.KeptnPhaseType, workloadInstance *klcv1alpha3.KeptnWorkloadInstance) { if appPreEvalStatus.IsFailed() { - r.EventSender.SendEvent(phase, "Warning", workloadInstance, apicommon.PhaseStateFailed, "has failed since app has failed", workloadInstance.GetVersion()) + r.EventSender.Emit(phase, "Warning", workloadInstance, apicommon.PhaseStateFailed, "has failed since app has failed", workloadInstance.GetVersion()) } } @@ -261,11 +261,11 @@ func (r *KeptnWorkloadInstanceReconciler) checkPreEvaluationStatusOfApp(ctx cont found, appVersion, err := r.getAppVersionForWorkloadInstance(ctx, workloadInstance) if err != nil { span.SetStatus(codes.Error, err.Error()) - r.EventSender.SendEvent(phase, "Warning", workloadInstance, "GetAppVersionFailed", "has failed since app could not be retrieved", workloadInstance.GetVersion()) + r.EventSender.Emit(phase, "Warning", workloadInstance, "GetAppVersionFailed", "has failed since app could not be retrieved", workloadInstance.GetVersion()) return true, fmt.Errorf(controllererrors.ErrCannotFetchAppVersionForWorkloadInstanceMsg + err.Error()) } else if !found { span.SetStatus(codes.Error, "app could not be found") - r.EventSender.SendEvent(phase, "Warning", workloadInstance, "AppVersionNotFound", "has failed since app could not be found", workloadInstance.GetVersion()) + r.EventSender.Emit(phase, "Warning", workloadInstance, "AppVersionNotFound", "has failed since app could not be found", workloadInstance.GetVersion()) return true, fmt.Errorf(controllererrors.ErrCannotFetchAppVersionForWorkloadInstanceMsg) } diff --git a/lifecycle-operator/webhooks/pod_mutator/pod_mutating_webhook.go b/lifecycle-operator/webhooks/pod_mutator/pod_mutating_webhook.go index 2f96390dfe..c291fe5616 100644 --- a/lifecycle-operator/webhooks/pod_mutator/pod_mutating_webhook.go +++ b/lifecycle-operator/webhooks/pod_mutator/pod_mutating_webhook.go @@ -288,7 +288,7 @@ func (a *PodMutatingWebhook) handleWorkload(ctx context.Context, logger logr.Log err = a.Client.Create(ctx, workload) if err != nil { logger.Error(err, "Could not create Workload") - a.EventSender.SendEvent(apicommon.PhaseCreateWorkload, "Warning", workload, apicommon.PhaseStateFailed, "could not create KeptnWorkload", workload.Spec.Version) + a.EventSender.Emit(apicommon.PhaseCreateWorkload, "Warning", workload, apicommon.PhaseStateFailed, "could not create KeptnWorkload", workload.Spec.Version) span.SetStatus(codes.Error, err.Error()) return err } @@ -312,7 +312,7 @@ func (a *PodMutatingWebhook) handleWorkload(ctx context.Context, logger logr.Log err = a.Client.Update(ctx, workload) if err != nil { logger.Error(err, "Could not update Workload") - a.EventSender.SendEvent(apicommon.PhaseUpdateWorkload, "Warning", workload, apicommon.PhaseStateFailed, "could not update KeptnWorkload", workload.Spec.Version) + a.EventSender.Emit(apicommon.PhaseUpdateWorkload, "Warning", workload, apicommon.PhaseStateFailed, "could not update KeptnWorkload", workload.Spec.Version) span.SetStatus(codes.Error, err.Error()) return err } @@ -340,7 +340,7 @@ func (a *PodMutatingWebhook) handleApp(ctx context.Context, logger logr.Logger, err = a.Client.Create(ctx, appCreationRequest) if err != nil { logger.Error(err, "Could not create AppCreationRequest") - a.EventSender.SendEvent(apicommon.PhaseCreateAppCreationRequest, "Warning", appCreationRequest, apicommon.PhaseStateFailed, "could not create KeptnAppCreationRequest", appCreationRequest.Spec.AppName) + a.EventSender.Emit(apicommon.PhaseCreateAppCreationRequest, "Warning", appCreationRequest, apicommon.PhaseStateFailed, "could not create KeptnAppCreationRequest", appCreationRequest.Spec.AppName) span.SetStatus(codes.Error, err.Error()) return err }