From f7b667b87872ab681cad72e92029a60bebcb91b4 Mon Sep 17 00:00:00 2001 From: attacker Date: Fri, 19 Jun 2026 07:52:46 +0000 Subject: [PATCH] =?UTF-8?q?feat(k8s-ui):=20HPA=20=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E9=86=92=E7=9B=AE=E5=8C=96=20+=20K8sWorkload?= =?UTF-8?q?s=20=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DeploymentDetail: - HPA 未配置时,状态卡片内直接显示「创建 HPA」按钮 - 无需切换到 HPA Tab 即可一键创建 K8sWorkloads: - 新增命名空间下拉选择器(自动加载集群全部 ns) - 切换集群时自动重置命名空间为「全部」 - Deployment/Pod 列表按命名空间过滤 - 统计卡片始终显示全量数据(不受 ns 过滤影响) --- .../src/components/k8s/DeploymentDetail.tsx | 14 +++++++- frontend/src/components/k8s/K8sWorkloads.tsx | 33 +++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/k8s/DeploymentDetail.tsx b/frontend/src/components/k8s/DeploymentDetail.tsx index 139d39e..c67b84e 100644 --- a/frontend/src/components/k8s/DeploymentDetail.tsx +++ b/frontend/src/components/k8s/DeploymentDetail.tsx @@ -220,7 +220,19 @@ export function DeploymentDetail({ clusterId, namespace, deploymentName, onBack

HPA

-

{hpas.length > 0 ? '已启用' : '未配置'}

+ {hpas.length > 0 ? ( +

已启用

+ ) : ( +
+

未配置

+ +
+ )}
diff --git a/frontend/src/components/k8s/K8sWorkloads.tsx b/frontend/src/components/k8s/K8sWorkloads.tsx index 45a06f6..d71ec72 100644 --- a/frontend/src/components/k8s/K8sWorkloads.tsx +++ b/frontend/src/components/k8s/K8sWorkloads.tsx @@ -22,6 +22,8 @@ export function K8sWorkloads() { const { toast } = useToast(); const [clusters, setClusters] = useState([]); const [selectedCluster, setSelectedCluster] = useState(''); + const [namespaces, setNamespaces] = useState([]); + const [selectedNamespace, setSelectedNamespace] = useState('all'); const [deployments, setDeployments] = useState([]); const [pods, setPods] = useState([]); const [loading, setLoading] = useState(false); @@ -43,6 +45,18 @@ export function K8sWorkloads() { useEffect(() => { loadClusters(); }, [loadClusters]); + // Load namespaces when cluster changes + const loadNamespaces = useCallback(async () => { + if (!selectedCluster) return; + try { + const res: any = await k8sApi.getNamespaces(selectedCluster); + const nsList: string[] = Array.isArray(res) ? res : (res?.list || res?.data || []); + setNamespaces(nsList); + } catch { setNamespaces([]); } + }, [selectedCluster]); + + useEffect(() => { loadNamespaces(); }, [loadNamespaces]); + const loadData = useCallback(async () => { if (!selectedCluster) return; setLoading(true); @@ -60,10 +74,12 @@ export function K8sWorkloads() { useEffect(() => { loadData(); }, [loadData]); const filteredDeps = deployments.filter((d) => - (d.name || '').toLowerCase().includes(search.toLowerCase()), + (d.name || '').toLowerCase().includes(search.toLowerCase()) && + (selectedNamespace === 'all' || d.namespace === selectedNamespace), ); const filteredPods = pods.filter((p) => - (p.name || '').toLowerCase().includes(search.toLowerCase()), + (p.name || '').toLowerCase().includes(search.toLowerCase()) && + (selectedNamespace === 'all' || p.namespace === selectedNamespace), ); const getPodStatusBadge = (status: string) => { @@ -112,7 +128,7 @@ export function K8sWorkloads() {

Deployment 与 Pod 运行状态

- { setSelectedCluster(v); setSelectedNamespace('all'); }}> @@ -122,6 +138,17 @@ export function K8sWorkloads() { ))} +