ronething commented on code in PR #2460:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/2460#discussion_r2188837845


##########
internal/provider/adc/adc.go:
##########
@@ -404,3 +415,150 @@ func prepareSyncFile(resources any) (string, func(), 
error) {
 
        return tmpFile.Name(), cleanup, nil
 }
+
+func (d *adcClient) handlerADCExecutionErrors(statusesMap 
map[string]types.ADCExecutionErrors) {
+       statusUpdateMap := d.resolveADCExecutionErrors(statusesMap)
+       d.handlerStatusUpdate(statusUpdateMap)
+}
+
+func (d *adcClient) handlerStatusUpdate(statusUpdateMap 
map[types.NamespacedNameKind][]string) {
+       for nnk, msgs := range statusUpdateMap {
+               d.updateStatus(nnk, cutils.NewConditionTypeAccepted(
+                       apiv2.ConditionReasonSyncFailed,
+                       false,
+                       0,
+                       strings.Join(msgs, "; "),
+               ))
+       }
+
+       for nnk := range d.statusUpdateMap {
+               if _, ok := statusUpdateMap[nnk]; !ok {
+                       d.updateStatus(nnk, cutils.NewConditionTypeAccepted(
+                               apiv2.ConditionReasonAccepted,
+                               true,
+                               0,
+                               "",
+                       ))
+               }
+       }
+       d.statusUpdateMap = statusUpdateMap
+}
+
+func (d *adcClient) resolveADCExecutionErrors(statusesMap 
map[string]types.ADCExecutionErrors) map[types.NamespacedNameKind][]string {
+       statusUpdateMap := map[types.NamespacedNameKind][]string{}
+       for configName, execErrors := range statusesMap {
+               log.Warnw("sync failed", zap.String("configName", configName), 
zap.Any("statuses", execErrors))
+               for _, execErr := range execErrors.Errors {
+                       for _, failedStatus := range execErr.FailedErrors {
+                               if len(failedStatus.FailedStatuses) == 0 {
+                                       resource, err := 
d.store.GetResources(execErr.Name)
+                                       if err != nil {
+                                               log.Errorw("failed to get 
resources from store", zap.String("configName", configName), zap.Error(err))
+                                               continue
+                                       }
+
+                                       fillStatusUpdateMapFunc := func(obj 
adctypes.Object) {
+                                               labels := obj.GetLabels()
+                                               statusKey := 
types.NamespacedNameKind{
+                                                       Name:      
labels[label.LabelName],
+                                                       Namespace: 
labels[label.LabelNamespace],
+                                                       Kind:      
labels[label.LabelKind],
+                                               }
+                                               if msgs, ok := 
statusUpdateMap[statusKey]; ok {
+                                                       
statusUpdateMap[statusKey] = append(msgs, failedStatus.Error())
+                                               } else {
+                                                       
statusUpdateMap[statusKey] = []string{failedStatus.Error()}
+                                               }
+                                       }
+                                       for _, service := range 
resource.Services {
+                                               fillStatusUpdateMapFunc(service)
+                                       }
+
+                                       for _, consumer := range 
resource.Consumers {
+                                               
fillStatusUpdateMapFunc(consumer)
+                                       }
+
+                                       for _, ssl := range resource.SSLs {
+                                               fillStatusUpdateMapFunc(ssl)
+                                       }
+
+                                       globalRuleItems, err := 
d.store.ListGlobalRules(configName)
+                                       if err != nil {
+                                               log.Errorw("failed to list 
global rules", zap.String("configName", configName), zap.Error(err))
+                                       }
+                                       for _, globalRule := range 
globalRuleItems {
+                                               
fillStatusUpdateMapFunc(globalRule)
+                                       }
+                                       continue
+                               }
+
+                               for _, status := range 
failedStatus.FailedStatuses {
+                                       id := status.Event.ResourceID
+                                       labels, err := 
d.store.GetResourceLabel(configName, status.Event.ResourceType, id)
+                                       if err != nil {
+                                               log.Errorw("failed to get 
resource label", zap.String("configName", configName), 
zap.String("resourceType", status.Event.ResourceType), zap.String("id", id), 
zap.Error(err))
+                                               continue
+                                       }
+                                       statusKey := types.NamespacedNameKind{
+                                               Name:      
labels[label.LabelName],
+                                               Namespace: 
labels[label.LabelNamespace],
+                                               Kind:      
labels[label.LabelKind],
+                                       }
+                                       msg := fmt.Sprintf("ServerAddr: %s, 
Error: %s",
+                                               failedStatus.ServerAddr, 
status.Reason)
+                                       if msgs, ok := 
statusUpdateMap[statusKey]; ok {
+                                               statusUpdateMap[statusKey] = 
append(msgs, msg)
+                                       } else {
+                                               statusUpdateMap[statusKey] = 
[]string{msg}
+                                       }

Review Comment:
   Ditto.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to