ronething commented on code in PR #2460: URL: https://github.com/apache/apisix-ingress-controller/pull/2460#discussion_r2188836717
########## 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()} + } Review Comment: what about append `statusUpdateMap[statusKey]` directly? `statusUpdateMap[statusKey] = append(statusUpdateMap[statusKey], failedStatus.Error())` -- 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