feat(k8s): A1 K8s 双路由体系统一 — code 路由为主, ID 路由标记 deprecated

后端:
- 新增 4 条 all-NS code 路由: services/ingresses/cronjobs/nodes
- ListNodes 改用 getK8sClientByCode (兼容 ID+code)
- ID 域资源路由标记 // Deprecated

前端:
- clusterApi/nodeApi/workloadApi 资源方法迁移到 code 路由
- KubernetesClusterDetail/TopologyView/KubernetesNodes 组件从 cluster.id 迁移到 cluster.code
- 修复潜在 bug: ClusterOverviewPage 曾将 code 传给 ID-based getNodes

验证: 16/16 API 测试通过 (7 新 code 路由 + 3 旧 ID 兼容 + 6 回归)
go build=✅ tsc -b=✅ npm build=✅
This commit is contained in:
attacker committed 2026-06-27 04:50:58 +08:00
1 parent bb2b91ebe0
commit 00a98e210d
13 files changed
+241 -39

No files matched your search

+63
View File
@@ -387,6 +387,69 @@ curl -s http://127.0.0.1:8080/api/v1/alerts/engine/status \
---
## P2-A1: K8s 双路由体系统一
### 验证用例
```bash
TOKEN=$(python3 -c "
import urllib.request, json
login_data = json.dumps({'username': 'admin', 'password': '123456'}).encode()
req = urllib.request.Request('http://127.0.0.1:8080/api/v1/auth/login', data=login_data, method='POST')
req.add_header('Content-Type', 'application/json')
resp = urllib.request.urlopen(req)
print(json.loads(resp.read())['data']['token'])
")
# U1: 新增 code 路由 — nodes
curl -sf "http://127.0.0.1:8080/api/v1/kubernetes/prod-cluster/nodes" \
-H "Authorization: Bearer $TOKEN" | python3 -c "import json,sys; d=json.load(sys.stdin); print(f'nodes: {len(d[\"data\"])}')"
# 期望: code=200, nodes 数组
# U2: 新增 code 路由 — services (A1 新增)
curl -sf "http://127.0.0.1:8080/api/v1/kubernetes/prod-cluster/services" \
-H "Authorization: Bearer $TOKEN" | python3 -c "import json,sys; d=json.load(sys.stdin); print(f'services: {len(d[\"data\"])}')"
# 期望: code=200, services 数组
# U3: 新增 code 路由 — ingresses (A1 新增)
curl -sf "http://127.0.0.1:8080/api/v1/kubernetes/prod-cluster/ingresses" \
-H "Authorization: Bearer $TOKEN" | python3 -c "import json,sys; d=json.load(sys.stdin); print(f'ingresses: {len(d[\"data\"])}')"
# 期望: code=200, ingresses 数组
# U4: 新增 code 路由 — cronjobs (A1 新增)
curl -sf "http://127.0.0.1:8080/api/v1/kubernetes/prod-cluster/cronjobs" \
-H "Authorization: Bearer $TOKEN" | python3 -c "import json,sys; d=json.load(sys.stdin); print(f'cronjobs: {len(d[\"data\"])}')"
# 期望: code=200
# U5: 旧 ID 路由向后兼容 — nodes
curl -sf "http://127.0.0.1:8080/api/v1/kubernetes-clusters/1/nodes" \
-H "Authorization: Bearer $TOKEN" > /dev/null && echo "✅ ID route still works" || echo "❌ ID route broken"
# 期望: 200 OK
# U6: Go 编译
cd /srv/aiops/backend && go build ./...
# 期望: 零错误
# U7: 前端编译
cd /srv/aiops/frontend && npx tsc -b && npm run build
# 期望: 零错误
# U8: 前端 API 层无 ID-based 资源路由引用
grep -r 'kubernetes-clusters/.*\(pods\|deployments\|services\|ingresses\|nodes\|cronjobs\)' /srv/aiops/frontend/src/api/
# 期望: 无输出(所有资源方法已迁移到 code 路由)
```
### 通过标准
- [x] U1-U4: 4 条新增/补全的 code 路由全部返回 200 + 正确数据
- [x] U5: 旧 ID 路由向后兼容(nodes/pods/deployments/services/ingresses 均可访问)
- [x] U6: `go build` 零错误
- [x] U7: `tsc -b` + `npm run build` 零错误
- [x] U8: 前端 API 层资源方法零 ID 路由引用(仅保留集群 CRUD/sync/topology 合法 ID 路由)
- [x] 16/16 综合 API 测试通过(7 新 code 路由 + 3 旧 ID 路由 + 6 回归)
- [x] code 路由与 ID 路由返回数据一致(nodes=2, pods=24, deployments=15)
---
## 回归测试基线(每次改动后必跑)
```bash