From fdcb398f74db84c3dd131bca9fbc17e3089100f2 Mon Sep 17 00:00:00 2001 From: tharindu1st Date: Thu, 16 Nov 2023 15:43:50 +0530 Subject: [PATCH] refactoring code --- .../controllers/cp/application_controller.go | 13 +++---------- common-controller/internal/utils/event_utils.go | 7 ++++--- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/common-controller/internal/operator/controllers/cp/application_controller.go b/common-controller/internal/operator/controllers/cp/application_controller.go index a5929d94b..04e09cac3 100644 --- a/common-controller/internal/operator/controllers/cp/application_controller.go +++ b/common-controller/internal/operator/controllers/cp/application_controller.go @@ -19,7 +19,6 @@ package cp import ( "context" - "fmt" "github.com/wso2/apk/adapter/pkg/logging" "github.com/wso2/apk/common-controller/internal/cache" @@ -37,7 +36,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" ) @@ -86,19 +84,14 @@ func NewApplicationController(mgr manager.Manager, subscriptionStore *cache.Subs func (applicationReconciler *ApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { _ = log.FromContext(ctx) applicationKey := req.NamespacedName - var applicationList = new(cpv1alpha2.ApplicationList) - loggers.LoggerAPKOperator.Infof("Reconciling application: %v", applicationKey.String()) - if err := applicationReconciler.client.List(ctx, applicationList); err != nil { - return reconcile.Result{}, fmt.Errorf("failed to get applications %s/%s", - applicationKey.Namespace, applicationKey.Name) - } + loggers.LoggerAPKOperator.Debugf("Reconciling application: %v", applicationKey.String()) var application cpv1alpha2.Application if err := applicationReconciler.client.Get(ctx, req.NamespacedName, &application); err != nil { if k8error.IsNotFound(err) { applicationSpec, found := applicationReconciler.ods.GetApplicationFromStore(applicationKey) - loggers.LoggerAPKOperator.Infof("Application cr not available in k8s") - loggers.LoggerAPKOperator.Infof("cached Application spec: %v,%v", applicationSpec, found) + loggers.LoggerAPKOperator.Debugf("Application cr not available in k8s") + loggers.LoggerAPKOperator.Debugf("cached Application spec: %v,%v", applicationSpec, found) if found { utils.SendAppDeletionEvent(applicationKey.Name, applicationSpec) applicationReconciler.ods.DeleteApplicationFromStore(applicationKey) diff --git a/common-controller/internal/utils/event_utils.go b/common-controller/internal/utils/event_utils.go index 6d4fa5fab..a1c34501d 100644 --- a/common-controller/internal/utils/event_utils.go +++ b/common-controller/internal/utils/event_utils.go @@ -46,7 +46,7 @@ func SendAppUpdateEvent(applicationUUID string, oldApplicationSpec cpv1alpha2.Ap Attributes: newApplicationSpec.Attributes, }, } - loggers.LoggerAPKOperator.Infof("Sending event to all clients: %v", &event) + loggers.LoggerAPKOperator.Debugf("Sending event to all clients: %v", &event) sendEvent(&event) sendDeleteApplicationKeyMappingEvent(applicationUUID, oldApplicationSpec) sendApplicationKeyMappingEvent(applicationUUID, newApplicationSpec) @@ -192,13 +192,13 @@ func sendApplicationKeyMappingEvent(applicationUUID string, applicationSpec cpv1 } } func sendEvent(event *subscription.Event) { - loggers.LoggerAPKOperator.Infof("Sending event to all clients: %v", event) + loggers.LoggerAPKOperator.Debugf("Sending event to all clients: %v", event) for clientID, stream := range GetAllClientConnections() { err := stream.Send(event) if err != nil { loggers.LoggerAPKOperator.Errorf("Error sending event to client %s: %v", clientID, err) } else { - loggers.LoggerAPKOperator.Infof("Event sent to client %s", clientID) + loggers.LoggerAPKOperator.Debugf("Event sent to client %s", clientID) } } } @@ -213,5 +213,6 @@ func SendInitialEvent(srv apkmgt.EventStreamService_StreamEventsServer) { Type: constants.AllEvnts, TimeStamp: milliseconds, } + loggers.LoggerAPKOperator.Debugf("Sending initial event to client: %v", &event) srv.Send(&event) }