// Kubernetes 命名空间资源 / YAML / 事件 / 容量 API // Logan.Li import { http } from '@/utils/request'; export const resourceApi = { getNamespaceServices: async (clusterCode: string, namespace: string) => http.get(`/kubernetes/${clusterCode}/namespace/${namespace}/services`), getNamespaceIngresses: async (clusterCode: string, namespace: string) => http.get(`/kubernetes/${clusterCode}/namespace/${namespace}/ingresses`), // 获取 IngressClass 列表,用于 Ingress 可视化编辑的下拉选择 // Logan.Li getIngressClasses: async (clusterCode: string) => http.get(`/kubernetes/${clusterCode}/ingressclasses`), getNamespaceConfigMaps: async (clusterCode: string, namespace: string) => http.get(`/kubernetes/${clusterCode}/namespace/${namespace}/configmaps`), getNamespaceSecrets: async (clusterCode: string, namespace: string) => http.get(`/kubernetes/${clusterCode}/namespace/${namespace}/secrets`), getPVCs: async (clusterCode: string, namespace: string) => http.get(`/kubernetes/${clusterCode}/namespace/${namespace}/pvcs`), deletePVC: async (clusterCode: string, namespace: string, name: string) => http.delete(`/kubernetes/${clusterCode}/namespace/${namespace}/pvcs/${name}`), getServiceAccounts: async (clusterCode: string, namespace: string) => http.get(`/kubernetes/${clusterCode}/namespace/${namespace}/serviceaccounts`), getRoles: async (clusterCode: string, namespace: string) => http.get(`/kubernetes/${clusterCode}/namespace/${namespace}/roles`), getRoleBindings: async (clusterCode: string, namespace: string) => http.get(`/kubernetes/${clusterCode}/namespace/${namespace}/rolebindings`), getResourceYaml: async (clusterCode: string, namespace: string, resource: string, name: string) => http.getRaw(`/kubernetes/${clusterCode}/namespace/${namespace}/${resource}/${name}/yaml`), updateResourceYaml: async (clusterCode: string, namespace: string, resource: string, name: string, yaml: string) => http.putRaw(`/kubernetes/${clusterCode}/namespace/${namespace}/${resource}/${name}/yaml`, yaml, 'application/yaml'), deleteResourceYaml: async (clusterCode: string, namespace: string, resource: string, name: string) => http.delete(`/kubernetes/${clusterCode}/namespace/${namespace}/${resource}/${name}/yaml`), getEvents: async (clusterCode: string, namespace?: string, type?: string) => { const params: Record = {}; if (namespace) params.namespace = namespace; if (type) params.type = type; return http.get(`/kubernetes/${clusterCode}/events`, params); }, getEventsSummary: async (clusterCode: string, namespace?: string, hours?: number) => { const params: Record = {}; if (namespace) params.namespace = namespace; if (hours) params.hours = hours; return http.get(`/kubernetes/${clusterCode}/events/summary`, params); }, getCapacity: async (clusterCode: string, namespace?: string) => { const params = namespace ? { namespace } : undefined; return http.get(`/kubernetes/${clusterCode}/capacity`, params); }, applyYAML: async (clusterCode: string, yaml: string) => http.post(`/kubernetes/${clusterCode}/yaml/apply`, { yaml }), };