Skip to content

Commit

Permalink
Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tharsanan1 committed Mar 28, 2024
1 parent 2a883d4 commit 241f3fd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions adapter/internal/operator/controllers/dp/api_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type APIReconciler struct {
successChannel *chan synchronizer.SuccessEvent
statusUpdater *status.UpdateHandler
mgr manager.Manager
controlPlaneEnabled bool
apiPropagationEnabled bool
}

// NewAPIController creates a new API controller instance. API Controllers watches for dpv1alpha2.API and gwapiv1b1.HTTPRoute.
Expand All @@ -123,7 +123,7 @@ func NewAPIController(mgr manager.Manager, operatorDataStore *synchronizer.Opera
}

conf := config.ReadConfigs()
apiReconciler.controlPlaneEnabled = conf.Adapter.ControlPlane.EnableAPIPropagation
apiReconciler.apiPropagationEnabled = conf.Adapter.ControlPlane.EnableAPIPropagation
predicates := []predicate.Predicate{predicate.NewPredicateFuncs(utils.FilterByNamespaces(conf.Adapter.Operator.Namespaces))}

if err := c.Watch(source.Kind(mgr.GetCache(), &dpv1alpha2.API{}), &handler.EnqueueRequestForObject{},
Expand Down Expand Up @@ -249,7 +249,7 @@ func (apiReconciler *APIReconciler) Reconcile(ctx context.Context, req ctrl.Requ
if err := apiReconciler.client.Get(ctx, req.NamespacedName, &apiCR); err != nil {
apiState, found := apiReconciler.ods.GetCachedAPI(req.NamespacedName)
if found && k8error.IsNotFound(err) {
if apiReconciler.controlPlaneEnabled {
if apiReconciler.apiPropagationEnabled {
// Convert api state to api cp data
loggers.LoggerAPKOperator.Info("Sending API deletion event to agent")
apiCpData := apiReconciler.convertAPIStateToAPICp(ctx, apiState)
Expand Down Expand Up @@ -430,7 +430,7 @@ func (apiReconciler *APIReconciler) resolveAPIRefs(ctx context.Context, api dpv1
loggers.LoggerAPKOperator.Debugf("Child references are retrieved successfully for API CR %s", apiRef.String())

if !api.Status.DeploymentStatus.Accepted {
if apiReconciler.controlPlaneEnabled {
if apiReconciler.apiPropagationEnabled {
// Publish the api data to CP
apiCpData := apiReconciler.convertAPIStateToAPICp(ctx, *apiState)
apiCpData.Event = controlplane.EventTypeCreate
Expand All @@ -442,7 +442,7 @@ func (apiReconciler *APIReconciler) resolveAPIRefs(ctx context.Context, api dpv1
return &synchronizer.APIEvent{EventType: constants.Create, Events: []synchronizer.APIState{*apiState}, UpdatedEvents: []string{}}, nil
} else if cachedAPI, events, updated :=
apiReconciler.ods.UpdateAPIState(apiRef, apiState); updated {
if apiReconciler.controlPlaneEnabled {
if apiReconciler.apiPropagationEnabled {
// Publish the api data to CP
apiCpData := apiReconciler.convertAPIStateToAPICp(ctx, *apiState)
apiCpData.Event = controlplane.EventTypeUpdate
Expand Down

0 comments on commit 241f3fd

Please sign in to comment.