feat(k8s): 完整 K8s 管理能力 — 日志/exec/扩缩容/HPA/CronJob/CI webhook

新增功能:
- Pod 日志查看 (GET logs, 支持 tail/container 参数)
- Pod exec 命令执行 (文件浏览 ls/cat/stat)
- Deployment 副本数加减 (scale PATCH)
- Deployment 滚动重启 (restart annotation)
- Deployment CI webhook (update-image, 滚动更新镜像)
- HPA 管理: 列表/创建(CPU+内存指标)/删除
- CronJob 管理: 列表/创建/暂停恢复/手动触发/删除
- Namespace 列表

K8s Client 扩展 (纯标准库, 零外部依赖):
- 新增 post/patch/delete HTTP 方法
- GetPodLogs/ScaleDeployment/UpdateDeploymentImage/RestartDeployment
- ExecInPod/ListHPAs/CreateHPA/DeleteHPA
- ListCronJobs/CreateCronJob/SuspendCronJob/DeleteCronJob/TriggerCronJob
- ListNamespaces

已知限制: Exec SPDY 交互终端需引入 remotecommand 包
This commit is contained in:
attacker committed 2026-06-19 06:45:00 +00:00
1 parent d3c3fb546d
commit 33e58ce25a
3 files changed
+884

No files matched your search

+22
View File
@@ -247,6 +247,28 @@ func Register(r *gin.Engine, db *gorm.DB, log *zap.Logger, cfg *config.Config, c
clusters.GET("/:id/ingresses", k8sHandler.ListIngresses)
clusters.GET("/:id/topology", k8sHandler.GetTopology) // 获取拓扑布局 // Logan.Li
clusters.PUT("/:id/topology", k8sHandler.SaveTopology) // 保存拓扑布局 // Logan.Li
// Pod 日志 // Logan.Li
clusters.GET("/:id/namespaces/:namespace/pods/:podName/logs", k8sHandler.GetPodLogs)
// Pod 终端 exec (命令执行 / 文件浏览) // Logan.Li
clusters.POST("/:id/namespaces/:namespace/pods/:podName/exec", k8sHandler.ExecInPod)
// Deployment 扩缩容 & 重启 // Logan.Li
clusters.POST("/:id/namespaces/:namespace/deployments/:name/scale", k8sHandler.ScaleDeployment)
clusters.POST("/:id/namespaces/:namespace/deployments/:name/restart", k8sHandler.RestartDeployment)
// Deployment CI 集成 (Webhook 更新镜像) // Logan.Li
clusters.POST("/:id/namespaces/:namespace/deployments/:name/update-image", k8sHandler.UpdateDeploymentImage)
// HPA 管理 // Logan.Li
clusters.GET("/:id/hpas", k8sHandler.ListHPAs)
clusters.POST("/:id/hpas", k8sHandler.CreateHPA)
clusters.DELETE("/:id/namespaces/:namespace/hpas/:name", k8sHandler.DeleteHPA)
// CronJob 管理 // Logan.Li
clusters.GET("/:id/cronjobs", k8sHandler.ListCronJobs)
clusters.POST("/:id/cronjobs", k8sHandler.CreateCronJob)
clusters.POST("/:id/namespaces/:namespace/cronjobs/:name/suspend", k8sHandler.SuspendCronJob)
clusters.POST("/:id/namespaces/:namespace/cronjobs/:name/trigger", k8sHandler.TriggerCronJob)
clusters.DELETE("/:id/namespaces/:namespace/cronjobs/:name", k8sHandler.DeleteCronJob)
// Namespace // Logan.Li
clusters.GET("/:id/namespaces", k8sHandler.ListNamespaces)
}
// 告警路由