diff --git a/Dockerfile.dev b/Dockerfile.dev index c528f9bc9..ff1bccbdd 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -3,7 +3,7 @@ ARG ENABLE_PROXY=false FROM node:22 AS node_builder ARG TARGETARCH -ARG ADC_COMMIT=250cef76fdb76e344bef3f42f85ac46ec71b17c8 +ARG ADC_COMMIT=78484e87a0168e0f86d130bfae8f808d0d1a1e41 WORKDIR /app diff --git a/api/adc/types.go b/api/adc/types.go index 501dedf76..a7eea8225 100644 --- a/api/adc/types.go +++ b/api/adc/types.go @@ -7,6 +7,7 @@ import ( "fmt" "strconv" "strings" + "time" "github.com/incubator4/go-resty-expr/expr" ) @@ -500,3 +501,45 @@ type RedirectConfig struct { URI string `json:"uri,omitempty" yaml:"uri,omitempty"` RetCode int `json:"ret_code,omitempty" yaml:"ret_code,omitempty"` } + +const ( + StatusSuccess = "success" + StatusFailed = "failed" + StatusPartialFailed = "partial_failed" +) + +type SyncResult struct { + Status string `json:"status"` + TotalResources int `json:"total_resources"` + SuccessCount int `json:"success_count"` + FailedCount int `json:"failed_count"` + Success []SyncStatus `json:"success"` + Failed []SyncStatus `json:"failed"` +} + +type SyncStatus struct { + Event StatusEvent `json:"event"` + FailedAt time.Time `json:"failed_at,omitempty"` + SyncedAt time.Time `json:"synced_at,omitempty"` + Reason string `json:"reason,omitempty"` + Response ResponseDetails `json:"response,omitempty"` +} + +type StatusEvent struct { + ResourceType string `json:"resourceType"` + Type string `json:"type"` + ResourceID string `json:"resourceId"` + ResourceName string `json:"resourceName"` + ParentID string `json:"parentId,omitempty"` +} + +type ResponseDetails struct { + Status int `json:"status"` + Headers map[string]string `json:"headers"` + Data ResponseData `json:"data"` +} + +type ResponseData struct { + Value map[string]interface{} `json:"value"` + ErrorMsg string `json:"error_msg"` +} diff --git a/internal/provider/adc/adc.go b/internal/provider/adc/adc.go index 70e67d44a..c87499087 100644 --- a/internal/provider/adc/adc.go +++ b/internal/provider/adc/adc.go @@ -3,6 +3,7 @@ package adc import ( "bytes" "context" + "encoding/json" "errors" "os" "os/exec" @@ -140,11 +141,13 @@ func (d *adcClient) sync(task Task) error { cmd.Env = append(cmd.Env, os.Environ()...) cmd.Env = append(cmd.Env, "ADC_EXPERIMENTAL_FEATURE_FLAGS=remote-state-file,parallel-backend-request", + "ADC_RUNNING_MODE=ingress", "ADC_BACKEND=api7ee", "ADC_SERVER="+d.ServerAddr, "ADC_TOKEN="+d.Token, ) + var result types.SyncResult if err := cmd.Run(); err != nil { stderrStr := stderr.String() stdoutStr := stdout.String() @@ -160,6 +163,21 @@ func (d *adcClient) sync(task Task) error { return errors.New("failed to sync resources: " + errMsg + ", exit err: " + err.Error()) } - log.Debugw("adc sync success", zap.String("taskname", task.Name)) + output := stdout.Bytes() + if err := json.Unmarshal(output, &result); err != nil { + log.Errorw("failed to unmarshal adc output", + zap.Error(err), + zap.String("stdout", string(output)), + ) + return errors.New("failed to unmarshal adc result: " + err.Error()) + } + + if result.FailedCount > 0 { + log.Errorw("adc sync failed", zap.Any("result", result)) + failed := result.Failed + return errors.New(failed[0].Reason) + } + + log.Debugw("adc sync success", zap.Any("result", result)) return nil }