diff --git a/frontend/src/pages/K8sResourceList.tsx b/frontend/src/pages/K8sResourceList.tsx index eafead5..e201ddb 100644 --- a/frontend/src/pages/K8sResourceList.tsx +++ b/frontend/src/pages/K8sResourceList.tsx @@ -191,6 +191,74 @@ export default function K8sResourceList() { return () => eventSource.close() } + const handleDeleteResource = async () => { + if (!deleteTarget) return + + setDeleting(true) + try { + let endpoint = ''; + let kind = ''; + + // Determine the correct endpoint based on the selected resource kind + switch (selectedKind.key) { + case 'pod': + endpoint = '/api/v1/k8s/pod/delete' + kind = 'Pod' + break + case 'deployment': + endpoint = '/api/v1/k8s/deployment/delete' + kind = 'Deployment' + break + case 'statefulset': + endpoint = '/api/v1/k8s/statefulset/delete' + kind = 'StatefulSet' + break + case 'service': + endpoint = '/api/v1/k8s/service/delete' + kind = 'Service' + break + case 'configmap': + endpoint = '/api/v1/k8s/configmap/delete' + kind = 'ConfigMap' + break + default: + throw new Error(`Unsupported resource kind: ${selectedKind.key}`) + } + + const res = await fetch(endpoint, { + method: 'DELETE', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + name: deleteTarget.name, + namespace: deleteTarget.namespace + }), + }) + + const result = await res.json() + + if (!res.ok) { + throw new Error(result.err || `Failed to delete ${kind}`) + } + + setSnackbar({ + open: true, + message: `${kind} 删除成功`, + severity: 'success' + }) + setDeleteDialogOpen(false) + setDeleteTarget(null) + fetchResources() + } catch (e: any) { + setSnackbar({ + open: true, + message: `删除失败: ${e.message}`, + severity: 'error' + }) + } finally { + setDeleting(false) + } + } + const handleDeletePod = async () => { if (!deleteTarget) return @@ -806,7 +874,7 @@ export default function K8sResourceList() {