feat: K8s集群监控数据展示 — 修复详情标签数据加载 + 补充Pod/Deployment/Service/Ingress种子数据 + deployment_count字段
This commit is contained in:
1 parent
1244a7cc6e
commit
8d47f8d86c
4 files changed
+340
-25
No files matched your search
@@ -109,18 +109,20 @@ export function K8sClusters() {
|
||||
|
||||
const loadClusterDetail = async (clusterId: string) => {
|
||||
try {
|
||||
// 后端 ListNodes/ListPods/etc 返回 data 直接为数组(非 {list,total})
|
||||
const [nodesRes, podsRes, depRes, svcRes, ingRes] = await Promise.all([
|
||||
k8sApi.getNodes(clusterId).catch(() => ({ list: [] })),
|
||||
k8sApi.getPods(clusterId).catch(() => ({ list: [] })),
|
||||
k8sApi.getDeployments(clusterId).catch(() => ({ list: [] })),
|
||||
k8sApi.getServices(clusterId).catch(() => ({ list: [] })),
|
||||
k8sApi.getIngresses(clusterId).catch(() => ({ list: [] })),
|
||||
k8sApi.getNodes(clusterId).catch(() => []),
|
||||
k8sApi.getPods(clusterId).catch(() => []),
|
||||
k8sApi.getDeployments(clusterId).catch(() => []),
|
||||
k8sApi.getServices(clusterId).catch(() => []),
|
||||
k8sApi.getIngresses(clusterId).catch(() => []),
|
||||
]);
|
||||
setNodes((nodesRes as any)?.list || []);
|
||||
setPods((podsRes as any)?.list || []);
|
||||
setDeployments((depRes as any)?.list || []);
|
||||
setServices((svcRes as any)?.list || []);
|
||||
setIngresses((ingRes as any)?.list || []);
|
||||
const toArray = (v: any) => (Array.isArray(v) ? v : (v?.list || []));
|
||||
setNodes(toArray(nodesRes));
|
||||
setPods(toArray(podsRes));
|
||||
setDeployments(toArray(depRes));
|
||||
setServices(toArray(svcRes));
|
||||
setIngresses(toArray(ingRes));
|
||||
} catch (e) {
|
||||
console.error('加载集群详情失败:', e);
|
||||
}
|
||||
@@ -683,12 +685,12 @@ export function K8sClusters() {
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={
|
||||
node.status === 'ready'
|
||||
(node.status || '').toLowerCase() === 'ready'
|
||||
? 'border-emerald-500/30 text-emerald-400 bg-emerald-500/10'
|
||||
: 'border-red-500/30 text-red-400 bg-red-500/10'
|
||||
}
|
||||
>
|
||||
{node.status === 'ready' ? 'Ready' : 'NotReady'}
|
||||
{(node.status || '').toLowerCase() === 'ready' ? 'Ready' : 'NotReady'}
|
||||
</Badge>
|
||||
</td>
|
||||
<td className="px-4 py-3 text-sm text-slate-300">
|
||||
@@ -739,9 +741,9 @@ export function K8sClusters() {
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={
|
||||
pod.status === 'running'
|
||||
(pod.status || '').toLowerCase() === 'running'
|
||||
? 'border-emerald-500/30 text-emerald-400 bg-emerald-500/10'
|
||||
: pod.status === 'pending'
|
||||
: (pod.status || '').toLowerCase() === 'pending'
|
||||
? 'border-amber-500/30 text-amber-400 bg-amber-500/10'
|
||||
: 'border-red-500/30 text-red-400 bg-red-500/10'
|
||||
}
|
||||
@@ -749,10 +751,10 @@ export function K8sClusters() {
|
||||
{pod.status}
|
||||
</Badge>
|
||||
</td>
|
||||
<td className="px-4 py-3 text-sm text-slate-300">{pod.restarts ?? 0}</td>
|
||||
<td className="px-4 py-3 text-sm text-slate-300">{pod.cpu}</td>
|
||||
<td className="px-4 py-3 text-sm text-slate-300">{pod.memory}</td>
|
||||
<td className="px-4 py-3 text-sm text-slate-400">{pod.node}</td>
|
||||
<td className="px-4 py-3 text-sm text-slate-300">{pod.restart_count ?? 0}</td>
|
||||
<td className="px-4 py-3 text-sm text-slate-300">{Number(pod.cpu_usage || 0).toFixed(1)}m</td>
|
||||
<td className="px-4 py-3 text-sm text-slate-300">{Number(pod.memory_usage || 0).toFixed(0)}Mi</td>
|
||||
<td className="px-4 py-3 text-sm text-slate-400">{pod.node_name}</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user