package handler import ( "net/http" "github.com/gin-gonic/gin" "flowstack/internal/database" "flowstack/internal/model" ) // argoApps 模拟 Argo CD 应用状态(演示用) var argoApps = []gin.H{ {"metadata": gin.H{"name": "aiops-backend"}, "spec": gin.H{"source": gin.H{"repoURL": "https://gitea.91ai.io/rlwj-lab/aiops-gitops.git", "path": "apps/aiops-backend", "targetRevision": "main"}, "destination": gin.H{"server": "https://k8s.prod", "namespace": "aiops"}}, "status": gin.H{"sync": gin.H{"status": "Synced"}, "health": gin.H{"status": "Healthy"}, "operationState": gin.H{"phase": "Succeeded"}}}, {"metadata": gin.H{"name": "aiops-web"}, "spec": gin.H{"source": gin.H{"repoURL": "https://gitea.91ai.io/rlwj-lab/aiops-gitops.git", "path": "apps/aiops-web", "targetRevision": "main"}, "destination": gin.H{"server": "https://k8s.prod", "namespace": "aiops"}}, "status": gin.H{"sync": gin.H{"status": "OutOfSync"}, "health": gin.H{"status": "Progressing"}, "operationState": gin.H{"phase": "Running"}}}, } // ListGitOpsApps GET /api/gitops/apps func ListGitOpsApps(c *gin.Context) { var apps []model.Application database.DB.Order("updated_at DESC").Find(&apps) c.JSON(http.StatusOK, apps) } // ArgoList GET /api/gitops/argo/apps func ArgoList(c *gin.Context) { c.JSON(http.StatusOK, argoApps) } // ArgoSync POST /api/gitops/argo/sync {appName} func ArgoSync(c *gin.Context) { var body struct { AppName string `json:"appName" binding:"required"` } if err := c.ShouldBindJSON(&body); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "appName required"}) return } c.JSON(http.StatusOK, gin.H{"success": true, "appName": body.AppName, "message": "Sync triggered"}) } // ArgoResourceTree GET /api/gitops/argo/:appName/tree func ArgoResourceTree(c *gin.Context) { name := c.Param("appName") c.JSON(http.StatusOK, gin.H{ "nodes": []gin.H{ {"uid": "1", "name": name + "-deployment", "kind": "Deployment", "namespace": "aiops", "status": "healthy", "resourceVersion": "v1"}, {"uid": "2", "name": name + "-svc", "kind": "Service", "namespace": "aiops", "status": "healthy", "resourceVersion": "v1"}, {"uid": "3", "name": name + "-hpa", "kind": "HorizontalPodAutoscaler", "namespace": "aiops", "status": "healthy", "resourceVersion": "v2"}, }, "edges": []gin.H{{"source": "1", "target": "2"}, {"source": "1", "target": "3"}}, }) } // ArgoDiff GET /api/gitops/argo/:appName/diff func ArgoDiff(c *gin.Context) { name := c.Param("appName") c.JSON(http.StatusOK, gin.H{ "diffs": []gin.H{ {"kind": "Deployment", "name": name, "namespace": "aiops", "diff": "- image: registry.example.com/aiops/" + name + ":202610261130\n+ image: registry.example.com/aiops/" + name + ":202610271200", "status": "modified"}, }, }) }