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 80996a7 commit 38a0b8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion adapter/internal/controlplane/eventPublisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func sendData() {

// AddToEventQueue adds the api event to queue
func AddToEventQueue(data APICPEvent) {
loggers.LoggerAPK.Infof("Event added to queue : %+v", data)
loggers.LoggerAPK.Debugf("Event added to CP Event queue : %+v", data)
eventQueue <- data
}

Expand Down
13 changes: 7 additions & 6 deletions adapter/internal/operator/controllers/dp/api_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ 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()
loggers.LoggerAPK.Infof("label section of the api : %+v", apiState.APIDefinition.ObjectMeta.Labels)
storedHash, hashFound := apiState.APIDefinition.ObjectMeta.Labels["apiHash"]
if !api.Status.DeploymentStatus.Accepted {
if apiReconciler.apiPropagationEnabled && !apiState.APIDefinition.Spec.SystemAPI {
Expand All @@ -471,7 +470,6 @@ func (apiReconciler *APIReconciler) resolveAPIRefs(ctx context.Context, api dpv1
apiHash := apiReconciler.getAPIHash(apiState)
if !hashFound || storedHash != apiHash {
apiReconciler.patchAPIHash(ctx, apiHash, apiState.APIDefinition.ObjectMeta.Name, apiState.APIDefinition.ObjectMeta.Namespace)
loggers.LoggerAPK.Infof("Ok: %+v, value: %+v nam: %+v", hashFound, storedHash, apiNamespacedName)
loggers.LoggerAPKOperator.Infof("API hash changed sending the API to agent")
apiReconciler.apiHashes[apiNamespacedName] = apiHash
// Publish the api data to CP
Expand Down Expand Up @@ -2321,7 +2319,11 @@ func (apiReconciler *APIReconciler) validateHTTPRouteExtRefs(apiState *synchroni

func (apiReconciler *APIReconciler) getAPIHash(apiState *synchronizer.APIState) string {
getUniqueID := func(obj interface{}, fields ...string) string {
loggers.LoggerAPK.Infof("Type of obj: %T", obj)
defer func() {
if r := recover(); r != nil {
loggers.LoggerAPK.Infof("Error occured while extracting values using reflection. Error: %+v", r)
}
}()
var sb strings.Builder
objValue := reflect.ValueOf(obj)
if objValue.Kind() == reflect.Ptr {
Expand Down Expand Up @@ -2400,11 +2402,11 @@ func (apiReconciler *APIReconciler) getAPIHash(apiState *synchronizer.APIState)
mutualSSLUniqueID += strconv.FormatBool(apiState.MutualSSL.Disabled) + apiState.MutualSSL.Required + strings.Join(apiState.MutualSSL.ClientCertificates, "")
}
joinedUniqueIDs = joinedUniqueIDs + strconv.FormatBool(apiState.SubscriptionValidation) + mutualSSLUniqueID
loggers.LoggerAPK.Infof("Prepared unique string: %s", joinedUniqueIDs)
hash := sha256.Sum256([]byte(joinedUniqueIDs))
hashedString := hex.EncodeToString(hash[:])
truncatedHash := hashedString[:62]
loggers.LoggerAPK.Infof("Prepared hash: %s, truncated hash: %s", hashedString, truncatedHash)
loggers.LoggerAPK.Debugf("Prepared unique string for api %s/%s: %s, Prepared hash: %s, Truncatd hash to store: %s", apiState.APIDefinition.ObjectMeta.Name,
apiState.APIDefinition.ObjectMeta.Namespace, joinedUniqueIDs, hashedString, truncatedHash)
return truncatedHash
}

Expand All @@ -2428,7 +2430,6 @@ func findProdSandEndpoints(apiState *synchronizer.APIState) (string, string, str
}
}
}
loggers.LoggerAPK.Infof("Returning endpoints: %s, %s", prodEndpoint, sandEndpoint)
return prodEndpoint, sandEndpoint, endpointProtocol
}

Expand Down

0 comments on commit 38a0b8f

Please sign in to comment.