feat(container): show business line workloads from Wayne

This commit is contained in:
mac
2026-07-22 14:57:11 +08:00
parent 89a23ef60d
commit 7f6f6fa41e
6 changed files with 824 additions and 2 deletions
+99
View File
@@ -0,0 +1,99 @@
import { getToken } from '@/utils/auth'
export interface ContainerServiceSummary {
businessLineId: number
businessLineName: string
namespaces: number
clusters: number
nodes: number
readyNodes: number
schedulableNodes: number
workloads: number
pods: number
readyPods: number
cpuUsed: number
cpuTotal: number
cpuPercent: number
memoryUsed: number
memoryTotal: number
memoryPercent: number
errors?: string[]
}
export interface ContainerWorkload {
name: string
cluster: string
namespace: string
workload: string
ready: string
readyPods: number
pods: number
image: string
biz: string
status: string
statusClass: string
}
export const emptyContainerServiceSummary: ContainerServiceSummary = {
businessLineId: 0,
businessLineName: '',
namespaces: 0,
clusters: 0,
nodes: 0,
readyNodes: 0,
schedulableNodes: 0,
workloads: 0,
pods: 0,
readyPods: 0,
cpuUsed: 0,
cpuTotal: 0,
cpuPercent: 0,
memoryUsed: 0,
memoryTotal: 0,
memoryPercent: 0,
}
export const containerServiceApi = {
async getSummary(businessLineId: number): Promise<ContainerServiceSummary> {
return authRequest(`/auth/api/v1/container-services/business-lines/${businessLineId}/summary`)
},
async listWorkloads(businessLineId: number): Promise<{ items: ContainerWorkload[]; summary: ContainerServiceSummary }> {
const data = await authRequest(`/auth/api/v1/container-services/business-lines/${businessLineId}/workloads`)
return {
items: Array.isArray(data.items) ? data.items : [],
summary: data.summary || emptyContainerServiceSummary,
}
},
}
async function authRequest(path: string, init: RequestInit = {}) {
const token = getToken()
const response = await fetch(path, {
...init,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
...(token ? { Authorization: `Bearer ${token}` } : {}),
...init.headers,
},
})
const text = await response.text()
const data = parseResponseBody(text)
if (!response.ok) {
const message = data?.error || data?.message || text || `HTTP ${response.status}`
throw new Error(message)
}
return data || {}
}
function parseResponseBody(text: string) {
if (!text.trim()) {
return {}
}
try {
return JSON.parse(text)
} catch {
return { error: text }
}
}