([]);
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 运行状态
-