Skip to content

Commit

Permalink
Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tharsanan1 committed Mar 31, 2024
1 parent 38a0b8f commit b468f4e
Showing 1 changed file with 0 additions and 8 deletions.
8 changes: 0 additions & 8 deletions adapter/internal/operator/controllers/dp/api_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,18 @@ type APIReconciler struct {
statusUpdater *status.UpdateHandler
mgr manager.Manager
apiPropagationEnabled bool
apiHashes map[string]string
}

// NewAPIController creates a new API controller instance. API Controllers watches for dpv1alpha2.API and gwapiv1b1.HTTPRoute.
func NewAPIController(mgr manager.Manager, operatorDataStore *synchronizer.OperatorDataStore, statusUpdater *status.UpdateHandler,
ch *chan *synchronizer.APIEvent, successChannel *chan synchronizer.SuccessEvent) error {
apiHash := make(map[string]string)
apiReconciler := &APIReconciler{
client: mgr.GetClient(),
ods: operatorDataStore,
ch: ch,
successChannel: successChannel,
statusUpdater: statusUpdater,
mgr: mgr,
apiHashes: apiHash,
}
ctx := context.Background()
c, err := controller.New(constants.APIController, mgr, controller.Options{Reconciler: apiReconciler})
Expand Down Expand Up @@ -258,8 +255,6 @@ func (apiReconciler *APIReconciler) Reconcile(ctx context.Context, req ctrl.Requ
var apiCR dpv1alpha2.API
if err := apiReconciler.client.Get(ctx, req.NamespacedName, &apiCR); err != nil {
apiState, found := apiReconciler.ods.GetCachedAPI(req.NamespacedName)
// remove the hash from the api hashes map if presents
delete(apiReconciler.apiHashes, req.NamespacedName.String())
if found && k8error.IsNotFound(err) {
if apiReconciler.apiPropagationEnabled {
// Convert api state to api cp data
Expand Down Expand Up @@ -446,15 +441,13 @@ func (apiReconciler *APIReconciler) resolveAPIRefs(ctx context.Context, api dpv1
}

loggers.LoggerAPKOperator.Debugf("Child references are retrieved successfully for API CR %s", apiRef.String())
apiNamespacedName := utils.NamespacedName(apiState.APIDefinition).String()
storedHash, hashFound := apiState.APIDefinition.ObjectMeta.Labels["apiHash"]
if !api.Status.DeploymentStatus.Accepted {
if apiReconciler.apiPropagationEnabled && !apiState.APIDefinition.Spec.SystemAPI {
apiHash := apiReconciler.getAPIHash(apiState)
if !hashFound || storedHash != apiHash {
apiReconciler.patchAPIHash(ctx, apiHash, apiState.APIDefinition.ObjectMeta.Name, apiState.APIDefinition.ObjectMeta.Namespace)
loggers.LoggerAPKOperator.Infof("API hash changed sending the API to agent")
apiReconciler.apiHashes[apiNamespacedName] = apiHash
// Publish the api data to CP
apiCpData := apiReconciler.convertAPIStateToAPICp(ctx, *apiState)
apiCpData.Event = controlplane.EventTypeCreate
Expand All @@ -471,7 +464,6 @@ func (apiReconciler *APIReconciler) resolveAPIRefs(ctx context.Context, api dpv1
if !hashFound || storedHash != apiHash {
apiReconciler.patchAPIHash(ctx, apiHash, apiState.APIDefinition.ObjectMeta.Name, apiState.APIDefinition.ObjectMeta.Namespace)
loggers.LoggerAPKOperator.Infof("API hash changed sending the API to agent")
apiReconciler.apiHashes[apiNamespacedName] = apiHash
// Publish the api data to CP
apiCpData := apiReconciler.convertAPIStateToAPICp(ctx, *apiState)
apiCpData.Event = controlplane.EventTypeUpdate
Expand Down

0 comments on commit b468f4e

Please sign in to comment.