Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Centralize workload cluster labels

rcourtmanbaf6f622ccac
diff --git a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
index 684cc263b4..4593493efb 100644
--- a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
+++ b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
@@ -142,6 +142,9 @@ resource display contract, so navigation context does not leak raw
The drawer's Kubernetes namespace/deployment tabs use the canonical
cluster-name helper for fetch keys, so the visible navigation label stays
separate from the backend cluster lookup contract.
+The workloads projection in `useWorkloads` also uses that same helper for pod
+context labels, keeping the dashboard's Kubernetes grouping aligned with the
+same canonical cluster-name boundary.
The aggregate `/api/charts/workloads-summary` endpoint now also has its own
explicit API p95 budget constant, aligned with the per-workload charts budget,
and `internal/api/slo_bench_test.go` must fail if that aggregate budget or its
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index d638678149..1485dc4f52 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -290,6 +290,9 @@ repeating a raw display-name fork.
The resource drawer's Kubernetes namespace and deployment tabs use the
canonical cluster-name helper for backend fetch keys, keeping lookup identity
separate from the governed display-label contract.
+The shared workloads projection in `useWorkloads` also uses that helper for
+pod context labels, so dashboard Kubernetes grouping follows the same
+canonical cluster-name contract instead of re-encoding the fallback locally.
That same contract also owns the canonical resource display-name fallback, so
name-or-ID presentation stays consistent between the unified AI adapter, the
AI resource context, and the shared resource selectors instead of being
diff --git a/frontend-modern/src/hooks/__tests__/useWorkloads.test.ts b/frontend-modern/src/hooks/__tests__/useWorkloads.test.ts
index b86f5e7db7..54f660a48e 100644
--- a/frontend-modern/src/hooks/__tests__/useWorkloads.test.ts
+++ b/frontend-modern/src/hooks/__tests__/useWorkloads.test.ts
@@ -160,6 +160,41 @@ describe('useWorkloads', () => {
dispose();
});
+ it('uses the canonical Kubernetes cluster name for pod context labels', async () => {
+ apiFetchJSONMock.mockResolvedValueOnce({
+ data: [
+ {
+ ...sampleResource,
+ id: 'pod-1',
+ type: 'pod',
+ name: 'pod-1',
+ kubernetes: {
+ clusterName: 'cluster-a',
+ context: 'cluster-context',
+ namespace: 'default',
+ podUid: 'pod-uid-1',
+ },
+ },
+ ],
+ meta: { totalPages: 1 },
+ });
+
+ let dispose = () => {};
+ let result: ReturnType<UseWorkloadsModule['useWorkloads']> | undefined;
+ createRoot((d) => {
+ dispose = d;
+ const [enabled] = createSignal(true);
+ result = useWorkloads(enabled);
+ });
+
+ await flushAsync();
+ await waitForWorkloadCount(() => result!.workloads().length);
+
+ expect(result!.workloads()[0]?.contextLabel).toBe('cluster-a');
+
+ dispose();
+ });
+
it('keeps workload reference stable when polling returns identical payload', async () => {
let dispose = () => {};
let result: ReturnType<UseWorkloadsModule['useWorkloads']> | undefined;
diff --git a/frontend-modern/src/hooks/useWorkloads.ts b/frontend-modern/src/hooks/useWorkloads.ts
index 85fe78888a..03f1d3e227 100644
--- a/frontend-modern/src/hooks/useWorkloads.ts
+++ b/frontend-modern/src/hooks/useWorkloads.ts
@@ -12,6 +12,7 @@ import { eventBus } from '@/stores/events';
import { resolvePlatformTypeFromSources } from '@/utils/sourcePlatforms';
import { normalizeDiskArray } from '@/utils/format';
import { resolveWorkloadTypeFromString } from '@/utils/workloads';
+import { getPreferredResourceClusterName } from '@/utils/resourceIdentity';
import type { WorkloadGuest } from '@/types/workloads';
const WORKLOADS_URL = '/api/resources?type=vm,system-container,app-container,pod';
@@ -411,7 +412,7 @@ const mapResourceToWorkload = (resource: APIResource): WorkloadGuest | null => {
: workloadType === 'app-container'
? resource.parentName || resource.docker?.hostname
: workloadType === 'pod'
- ? resource.kubernetes?.clusterName || resource.kubernetes?.context
+ ? getPreferredResourceClusterName(resource)
: undefined,
clusterName:
(resource.proxmox?.clusterName || resource.identity?.clusterName || '').trim() || undefined,
diff --git a/frontend-modern/src/utils/resourceIdentity.ts b/frontend-modern/src/utils/resourceIdentity.ts
index f30b62cf78..5b766f4ea2 100644
--- a/frontend-modern/src/utils/resourceIdentity.ts
+++ b/frontend-modern/src/utils/resourceIdentity.ts
@@ -20,6 +20,23 @@ export type ResourceIdentityRow = {
value: string;
};
+type ResourceClusterNameLike = {
+ name?: string | null;
+ clusterId?: string | null;
+ platformData?: {
+ kubernetes?: {
+ clusterName?: string | null;
+ context?: string | null;
+ clusterId?: string | null;
+ } | null;
+ } | null;
+ kubernetes?: {
+ clusterName?: string | null;
+ context?: string | null;
+ clusterId?: string | null;
+ } | null;
+};
+
type APINormalizedIdentityResource = {
id: string;
name?: string;
@@ -301,16 +318,14 @@ export const getPreferredResourceHostname = (resource: Resource): string | undef
);
};
-export const getPreferredResourceClusterName = (resource: Resource): string | undefined =>
+export const getPreferredResourceClusterName = (
+ resource: ResourceClusterNameLike,
+): string | undefined =>
(() => {
- const platformData = getPlatformDataRecord(resource);
- const kubernetes = platformData?.kubernetes as Record<string, unknown> | undefined;
+ const kubernetes = resource.kubernetes || resource.platformData?.kubernetes;
return (
- asTrimmedString(resource.kubernetes?.clusterName) ||
asTrimmedString(kubernetes?.clusterName) ||
- asTrimmedString(resource.kubernetes?.context) ||
asTrimmedString(kubernetes?.context) ||
- asTrimmedString(resource.kubernetes?.clusterId) ||
asTrimmedString(kubernetes?.clusterId) ||
asTrimmedString(resource.clusterId) ||
asTrimmedString(resource.name)