feat(k8s): M14 Namespace 管理看板(资源配额 + 命名空间 CRUD)
- 后端: ListNamespacesDetailed/CreateNamespace/DeleteNamespace/ListResourceQuotas/ListLimitRanges - 后端: GetNamespacesDetail handler (6 API calls aggregate, not N×3) - 后端: CreateNamespaceHandler + DeleteNamespaceHandler (system NS protection) - 前端: NamespaceManagementPage.tsx (~280行) — 表格+概览卡片+创建/删除弹框 - 路由: GET/POST/DELETE /:clusterCode/namespaces + GET /namespace/:ns/detail - 验证: 9/9 通过 (urllib), TS 零错误, Vite 构建成功
This commit is contained in:
1 parent
c7b61968bc
commit
8240a88a84
33 files changed
+2029
-71
No files matched your search
+70
@@ -478,3 +478,73 @@ cd frontend && npx tsc --noEmit && npm run build 2>&1 | tail -3
|
||||
- [x] 前端 4 类图表正确渲染(柱状图×2 + 雷达图 + 饼图)
|
||||
- [x] 详细对比表格可点击跳转集群概览
|
||||
- [x] totals 聚合正确(cluster_count/node_count/pod_count/deployment_count/service_count)
|
||||
|
||||
---
|
||||
|
||||
## M14: Namespace 管理看板(资源配额 + 命名空间 CRUD)
|
||||
|
||||
### 验证用例
|
||||
|
||||
```bash
|
||||
# U1: 登录获取 Token
|
||||
TOKEN=$(python3 -c "
|
||||
import urllib.request, json
|
||||
login_data = json.dumps({'username': 'admin', 'password': 'admin123'}).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'])
|
||||
")
|
||||
|
||||
# U2: 命名空间详情 API(含资源计数+配额状态)
|
||||
curl -s "http://127.0.0.1:8080/api/v1/kubernetes/prod-cluster/namespaces/detail" \
|
||||
-H "Authorization: Bearer $TOKEN" | jq '.data | length'
|
||||
# 期望: 返回所有命名空间(含 status/age/labels/resource_counts)
|
||||
|
||||
# U3: 字段完整性
|
||||
curl -s "http://127.0.0.1:8080/api/v1/kubernetes/prod-cluster/namespaces/detail" \
|
||||
-H "Authorization: Bearer $TOKEN" | jq '.data[0] | keys'
|
||||
# 期望: 含 name/status/age/labels/resource_counts/has_resource_quota/has_limit_range
|
||||
|
||||
# U4: 创建命名空间
|
||||
curl -s -X POST "http://127.0.0.1:8080/api/v1/kubernetes/prod-cluster/namespaces" \
|
||||
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
|
||||
-d '{"name":"test-ns-m14","labels":{"env":"test"}}'
|
||||
# 期望: code=200, message="命名空间创建成功"
|
||||
|
||||
# U5: 创建后验证存在于列表
|
||||
curl -s "http://127.0.0.1:8080/api/v1/kubernetes/prod-cluster/namespaces/detail" \
|
||||
-H "Authorization: Bearer $TOKEN" | jq '[.data[] | select(.name=="test-ns-m14")] | length'
|
||||
# 期望: 1
|
||||
|
||||
# U6: 删除命名空间
|
||||
curl -s -X DELETE "http://127.0.0.1:8080/api/v1/kubernetes/prod-cluster/namespaces/test-ns-m14" \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
# 期望: code=200, message="命名空间已删除"
|
||||
|
||||
# U7: 系统命名空间删除保护
|
||||
curl -s -X DELETE "http://127.0.0.1:8080/api/v1/kubernetes/prod-cluster/namespaces/kube-system" \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
# 期望: code=403, message="禁止删除系统命名空间: kube-system"
|
||||
|
||||
# U8: SPA 路由
|
||||
curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1/kubernetes/prod-cluster/namespaces
|
||||
# 期望: 200
|
||||
|
||||
# U9: TypeScript + Vite 构建
|
||||
cd frontend && npx tsc --noEmit && npm run build 2>&1 | tail -3
|
||||
# 期望: 零错误 + built in Ns
|
||||
```
|
||||
|
||||
### 通过标准
|
||||
- [x] U2: Namespaces Detail API 返回完整命名空间列表(含 status/age/resource_counts)
|
||||
- [x] U3: 每个命名空间包含 7 个字段(name/status/age/labels/resource_counts/has_resource_quota/has_limit_range)
|
||||
- [x] U4: 创建命名空间 API 返回 200
|
||||
- [x] U5: 创建后命名空间出现在列表中
|
||||
- [x] U6: 删除命名空间 API 返回 200
|
||||
- [x] U7: 系统命名空间删除被拦截(403)
|
||||
- [x] U8: SPA 路由返回 200
|
||||
- [x] U9: TypeScript 零编译错误 + Vite 构建成功
|
||||
- [x] 前端命名空间管理页表格正确渲染(名称/状态/年龄/资源计数/配额/操作)
|
||||
- [x] 创建/删除弹框功能正常
|
||||
- [x] 集群概览页「管理全部」链接跳转正常
|
||||
Reference in new issue
Block a user