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 Kubernetes context prefix

rcourtman1de58364945e
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 429c29035b..0b2e758f99 100644
--- a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
+++ b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
@@ -139,6 +139,10 @@ The shared workloads-link helper used by the resource drawer and table now
also routes its Kubernetes-cluster fallback through the same preferred
resource display contract, so navigation context does not leak raw
`displayName` values for governed clusters.
+That same workloads-link path and the dashboard workload projection now also
+share the canonical Kubernetes context prefix helper, so route labels and pod
+grouping keep using the same cluster-context source of truth instead of
+rebuilding the `clusterName`/`context`/`clusterId` prefix locally.
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.
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 3fdc736869..686424cace 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -296,6 +296,10 @@ canonical cluster-name contract instead of re-encoding the fallback locally.
The drawer's discovery mapper also reuses that helper for pod fallback agent
IDs, so the resource-detail path and the dashboard path stay aligned on the
same cluster-name source of truth.
+The dashboard workload projection and workloads-link route helpers also share
+the same Kubernetes context prefix helper, so pod grouping and cluster
+navigation keep the same cluster-context prefix before any surface-specific
+display fallback is applied.
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/components/Dashboard/__tests__/Dashboard.performance.contract.test.tsx b/frontend-modern/src/components/Dashboard/__tests__/Dashboard.performance.contract.test.tsx
index 0712ef138b..b57be00ea4 100644
--- a/frontend-modern/src/components/Dashboard/__tests__/Dashboard.performance.contract.test.tsx
+++ b/frontend-modern/src/components/Dashboard/__tests__/Dashboard.performance.contract.test.tsx
@@ -297,6 +297,18 @@ describe('Dashboard performance contract', () => {
expect(filtered).toHaveLength(1);
expect(rawFiltered).toHaveLength(0);
});
+
+ it('keeps projected pod context keys aligned with the canonical cluster label', () => {
+ const guest = makeGuest(1, {
+ type: 'pod',
+ workloadType: 'pod',
+ contextLabel: 'cluster-a',
+ instance: 'cluster-b',
+ node: 'worker-a',
+ });
+
+ expect(getKubernetesContextKey(guest as any)).toBe('cluster-a');
+ });
});
describe('Workload windowing contracts', () => {
diff --git a/frontend-modern/src/components/Infrastructure/workloadsLink.ts b/frontend-modern/src/components/Infrastructure/workloadsLink.ts
index 52bdb7d607..f6a218b4c6 100644
--- a/frontend-modern/src/components/Infrastructure/workloadsLink.ts
+++ b/frontend-modern/src/components/Infrastructure/workloadsLink.ts
@@ -7,27 +7,9 @@ import {
import {
getPreferredResourceDisplayName,
getPreferredWorkloadsAgentHint,
+ getPreferredResourceKubernetesContext,
} from '@/utils/resourceIdentity';
-
-type ProxmoxPlatformData = {
- nodeName?: string;
-};
-
-type AgentPlatformData = {
- hostname?: string;
-};
-
-type KubernetesPlatformData = {
- clusterId?: string;
- clusterName?: string;
- context?: string;
-};
-
-type PlatformData = {
- proxmox?: ProxmoxPlatformData;
- agent?: AgentPlatformData;
- kubernetes?: KubernetesPlatformData;
-};
+import { requiresGovernedResourceDisplay } from '@/types/resource';
const firstNonEmpty = (values: Array<string | undefined | null>): string | undefined => {
for (const value of values) {
@@ -39,24 +21,18 @@ const firstNonEmpty = (values: Array<string | undefined | null>): string | undef
};
const resolveKubernetesContext = (resource: Resource): string | undefined => {
- const platformData = resource.platformData as PlatformData | undefined;
- const kubernetes = platformData?.kubernetes;
+ const kubernetesContext = getPreferredResourceKubernetesContext(resource);
if (resource.type === 'k8s-cluster') {
+ const displayLabel = requiresGovernedResourceDisplay(resource.policy)
+ ? getPreferredResourceDisplayName(resource)
+ : resource.displayName?.trim() || resource.name?.trim() || undefined;
return firstNonEmpty([
- kubernetes?.clusterName,
- kubernetes?.context,
- kubernetes?.clusterId,
- resource.clusterId,
- getPreferredResourceDisplayName(resource),
+ kubernetesContext,
+ displayLabel,
]);
}
if (resource.type === 'k8s-node') {
- return firstNonEmpty([
- kubernetes?.clusterName,
- kubernetes?.context,
- kubernetes?.clusterId,
- resource.clusterId,
- ]);
+ return kubernetesContext;
}
return undefined;
};
diff --git a/frontend-modern/src/hooks/__tests__/useWorkloads.test.ts b/frontend-modern/src/hooks/__tests__/useWorkloads.test.ts
index 54f660a48e..997c3ed8af 100644
--- a/frontend-modern/src/hooks/__tests__/useWorkloads.test.ts
+++ b/frontend-modern/src/hooks/__tests__/useWorkloads.test.ts
@@ -191,6 +191,7 @@ describe('useWorkloads', () => {
await waitForWorkloadCount(() => result!.workloads().length);
expect(result!.workloads()[0]?.contextLabel).toBe('cluster-a');
+ expect(result!.workloads()[0]?.instance).toBe('cluster-a');
dispose();
});
diff --git a/frontend-modern/src/hooks/useWorkloads.ts b/frontend-modern/src/hooks/useWorkloads.ts
index 03f1d3e227..d339f06d63 100644
--- a/frontend-modern/src/hooks/useWorkloads.ts
+++ b/frontend-modern/src/hooks/useWorkloads.ts
@@ -12,7 +12,10 @@ 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 {
+ getPreferredResourceClusterName,
+ getPreferredResourceKubernetesContext,
+} from '@/utils/resourceIdentity';
import type { WorkloadGuest } from '@/types/workloads';
const WORKLOADS_URL = '/api/resources?type=vm,system-container,app-container,pod';
@@ -281,12 +284,11 @@ const mapResourceToWorkload = (resource: APIResource): WorkloadGuest | null => {
const name = (resource.name || resource.id || '').toString().trim();
const node = resource.node ?? resource.proxmox?.nodeName ?? resource.kubernetes?.nodeName ?? '';
+ const kubernetesContext = getPreferredResourceKubernetesContext(resource);
const instance =
resource.instance ??
resource.proxmox?.instance ??
- resource.kubernetes?.clusterId ??
- resource.kubernetes?.clusterName ??
- resource.kubernetes?.context ??
+ kubernetesContext ??
resource.proxmox?.clusterName ??
resource.identity?.clusterName ??
'';
diff --git a/frontend-modern/src/utils/__tests__/resourceIdentity.test.ts b/frontend-modern/src/utils/__tests__/resourceIdentity.test.ts
index ca901f501f..c254bae16e 100644
--- a/frontend-modern/src/utils/__tests__/resourceIdentity.test.ts
+++ b/frontend-modern/src/utils/__tests__/resourceIdentity.test.ts
@@ -11,6 +11,7 @@ import {
getInfrastructureDiscoveryHostname,
getInfrastructureMetadataId,
getPreferredResourceClusterName,
+ getPreferredResourceKubernetesContext,
getPreferredResourceDisplayName,
getPreferredResourceHostname,
getPreferredWorkloadsAgentHint,
@@ -183,6 +184,22 @@ describe('resourceIdentity', () => {
expect(getPreferredResourceClusterName(resource)).toBe('cluster-a');
});
+ it('prefers the canonical Kubernetes context prefix without display fallbacks', () => {
+ const resource = makeResource({
+ type: 'k8s-node',
+ name: 'secret-node',
+ displayName: 'Governed Node',
+ clusterId: 'cluster-override',
+ kubernetes: {
+ clusterName: 'cluster-a',
+ context: 'cluster-context',
+ clusterId: 'cluster-a-id',
+ },
+ });
+
+ expect(getPreferredResourceKubernetesContext(resource)).toBe('cluster-a');
+ });
+
it('builds agent-like aliases for legacy summary/detail surfaces', () => {
const agent = {
id: 'agent-explicit',
diff --git a/frontend-modern/src/utils/resourceIdentity.ts b/frontend-modern/src/utils/resourceIdentity.ts
index 5b766f4ea2..af108cd0f2 100644
--- a/frontend-modern/src/utils/resourceIdentity.ts
+++ b/frontend-modern/src/utils/resourceIdentity.ts
@@ -332,6 +332,18 @@ export const getPreferredResourceClusterName = (
);
})();
+export const getPreferredResourceKubernetesContext = (
+ resource: ResourceClusterNameLike,
+): string | undefined => {
+ const kubernetes = resource.kubernetes || resource.platformData?.kubernetes;
+ return (
+ asTrimmedString(kubernetes?.clusterName) ||
+ asTrimmedString(kubernetes?.context) ||
+ asTrimmedString(kubernetes?.clusterId) ||
+ asTrimmedString(resource.clusterId)
+ );
+};
+
export const getPreferredResourceDisplayName = (resource: Resource): string =>
requiresGovernedResourceDisplay(resource.policy)
? getResourcePolicyDisplayLabel(resource)