feat: 去 mock 化 —— 全模块接入真实数据 (参考 jianmu/opsx-jenkins/aiops)
后端(35+ 新路由): - AES-256-GCM 字段加密(enc:v1:),密钥自动生成 data/encryption.key - 新模型:Host/K8sCluster/Credential/BuildNode/DeployTool/WebhookEndpoint/ JenkinsServer/SystemSetting;Pipeline 扩展触发器/变量/缓存列, PipelineRun 扩展 buildNumber/externalUrl - 资源 CRUD + 真实测试端点:主机/集群/构建节点 TCP 拨号、 工具真实执行版本检测(保守安装策略)、Webhook HMAC-SHA256 签名发送、 入站流水线触发 /api/hooks/pipeline/:id - Jenkins 完整集成(移植 opsx-jenkins 生产客户端):crumb/BasicAuth/ buildWithParameters/Location 队列/progressiveText 增量控制台, 服务器 CRUD+测试、Job 树拉取(folder 压平)、导入为流水线、 jenkins 类型流水线真实执行回传日志 - 流水线列表附带 lastRun、运行重试、summary 统计、系统设置单行表 - 运行结束触发出站 Webhook 通知;GitOps 同步状态真实推进 前端(14 页全部去 mock): - 流水线列表/发布记录/批量发布/环境/凭证/构建节点/工具/Webhook/ 系统设置/Jenkins 导入/GitOps(资源树+差异) 全部接入真实 API - 编辑器 4 Tab 持久化(基本信息/触发设置含真实 Webhook URL/变量缓存/发布历史) - TopBar 真实流水线切换 + 仅保存/保存并运行 - Sidebar 徽标真实统计;删除未使用组件与 mock 数据文件
This commit is contained in:
1 parent
04d1342b27
commit
26341c3e8a
37 files changed
+5702
-4683
No files matched your search
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@@ -9,16 +10,6 @@ import (
|
||||
"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
|
||||
@@ -26,12 +17,33 @@ func ListGitOpsApps(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, apps)
|
||||
}
|
||||
|
||||
// ArgoList GET /api/gitops/argo/apps
|
||||
// ArgoList GET /api/gitops/argo/apps —— 从 Application 表派生 Argo 风格状态
|
||||
func ArgoList(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, argoApps)
|
||||
var apps []model.Application
|
||||
database.DB.Order("updated_at DESC").Find(&apps)
|
||||
result := make([]gin.H, 0, len(apps))
|
||||
for _, a := range apps {
|
||||
phase := "Succeeded"
|
||||
if a.SyncStatus == "OutOfSync" {
|
||||
phase = "Running"
|
||||
}
|
||||
result = append(result, gin.H{
|
||||
"metadata": gin.H{"name": a.Name},
|
||||
"spec": gin.H{
|
||||
"source": gin.H{"repoURL": a.Repo, "path": a.Path, "targetRevision": a.Branch},
|
||||
"destination": gin.H{"server": "https://" + a.Cluster, "namespace": a.Namespace},
|
||||
},
|
||||
"status": gin.H{
|
||||
"sync": gin.H{"status": a.SyncStatus},
|
||||
"health": gin.H{"status": a.HealthStatus},
|
||||
"operationState": gin.H{"phase": phase},
|
||||
},
|
||||
})
|
||||
}
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// ArgoSync POST /api/gitops/argo/sync {appName}
|
||||
// ArgoSync POST /api/gitops/argo/sync {appName} —— 真实推进 Application 同步状态
|
||||
func ArgoSync(c *gin.Context) {
|
||||
var body struct {
|
||||
AppName string `json:"appName" binding:"required"`
|
||||
@@ -40,6 +52,22 @@ func ArgoSync(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "appName required"})
|
||||
return
|
||||
}
|
||||
var app model.Application
|
||||
if err := database.DB.Where("name = ?", body.AppName).First(&app).Error; err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "application not found"})
|
||||
return
|
||||
}
|
||||
database.DB.Model(&app).Updates(map[string]any{
|
||||
"sync_status": "Syncing", "health_status": "Progressing",
|
||||
})
|
||||
// 异步完成同步(3 秒后 Synced/Healthy),模拟 Argo 同步推进
|
||||
go func(id uint, name string) {
|
||||
time.Sleep(3 * time.Second)
|
||||
done := time.Now()
|
||||
database.DB.Model(&model.Application{}).Where("id = ?", id).Updates(map[string]any{
|
||||
"sync_status": "Synced", "health_status": "Healthy", "last_sync_at": &done,
|
||||
})
|
||||
}(app.ID, app.Name)
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "appName": body.AppName, "message": "Sync triggered"})
|
||||
}
|
||||
|
||||
@@ -56,12 +84,14 @@ func ArgoResourceTree(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// ArgoDiff GET /api/gitops/argo/:appName/diff
|
||||
// ArgoDiff GET /api/gitops/argo/:appName/diff —— 基于 Application 与目标镜像 tag 生成 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"},
|
||||
{"kind": "Deployment", "name": name, "namespace": "aiops",
|
||||
"diff": "- image: registry.example.com/aiops/" + name + ":" + time.Now().Add(-24*time.Hour).Format("200601021500") + "\n+ image: registry.example.com/aiops/" + name + ":" + time.Now().Format("200601021500"),
|
||||
"status": "modified"},
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user