From e7a376db7003927c5088ba15cc9f374b75296966 Mon Sep 17 00:00:00 2001 From: gitlawr Date: Thu, 21 May 2026 11:19:49 +0800 Subject: [PATCH] refactor: adapt org-namespace lookup to principal name rename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tracks the gpustack identity-consolidation effort: the unified ``principals`` table's URL-safe identifier column was renamed ``slug`` → ``name`` (with the legacy display ``name`` → ``display_name``). The enterprise plugin's persisted org caches (``organizationList``, ``allOrganizations`` in localStorage) now write ``name`` instead of ``slug`` on each Organization row. ``getCurrentOrgNamespace`` reads those caches to compose the k8s namespace (``gpustack-{name}``) for GPU-instance / storage CRDs. Updated to read ``item.name`` so namespace resolution stays in sync with what the enterprise plugin writes — otherwise every gpu-service write would fall through to ``gpustack-default`` even when the user has an Org context. Stale ``slug`` references in surrounding comments also retitled to ``name`` to avoid divergence between code and prose. The namespace format itself (``gpustack-{...}``) is unchanged — only the column it sources is. --- src/atoms/user.ts | 12 +++++++----- src/pages/cluster-management/config/types.ts | 2 +- src/pages/gpu-service/instances/index.tsx | 2 +- .../instances/services/use-create-instance.ts | 2 +- .../instances/services/use-update-instance.ts | 2 +- src/pages/gpu-service/storage/index.tsx | 2 +- .../storage/services/use-create-storage.ts | 2 +- .../storage/services/use-query-storage.ts | 2 +- .../storage/services/use-update-storage.ts | 2 +- 9 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/atoms/user.ts b/src/atoms/user.ts index 67370036..ecfa1134 100644 --- a/src/atoms/user.ts +++ b/src/atoms/user.ts @@ -30,9 +30,11 @@ export const initialPasswordAtom = atomWithStorage( // Namespace the server creates for an Org's resources on each Kubernetes // cluster. The format must match the backend's ``get_namespace_name`` -// helper — ``gpustack-{slug}`` — because the GPU-instance / storage CRDs +// helper — ``gpustack-{name}`` — because the GPU-instance / storage CRDs // (worker.gpustack.ai/v1) are namespaced and the server-side admission -// keys off this exact name. +// keys off this exact name. The identifier column on the unified +// Principal table is now ``name`` (post identity-consolidation rename +// of the legacy ``slug``); the namespace prefix is unchanged. // // Resolution path: // 1. The Org the caller is currently acting under — the enterprise @@ -75,7 +77,7 @@ const getStoredCurrentOrgId = (): number | null => { // the caller's member orgs; ``allOrganizations`` is admin-only (every // Org on the platform) so admin sessions can resolve any owner Org id. // Both are checked because ``currentOrganizationId`` is null in the -// admin "All" view but a member org's slug might still cover the +// admin "All" view but a member org's ``name`` might still cover the // cluster-owner fallback. const ORG_CACHE_KEYS = ['organizationList', 'allOrganizations'] as const; @@ -89,10 +91,10 @@ const lookupOrgNamespace = (id: number | null): string | null => { try { const raw = localStorage.getItem(key); if (!raw) continue; - const list = JSON.parse(raw) as Array<{ id: number; slug?: string }>; + const list = JSON.parse(raw) as Array<{ id: number; name?: string }>; if (!Array.isArray(list)) continue; const match = list.find((item) => String(item?.id) === target); - if (match?.slug) return `gpustack-${match.slug}`; + if (match?.name) return `gpustack-${match.name}`; } catch { // ignore malformed cache; continue checking other keys } diff --git a/src/pages/cluster-management/config/types.ts b/src/pages/cluster-management/config/types.ts index c587c453..fa48277c 100644 --- a/src/pages/cluster-management/config/types.ts +++ b/src/pages/cluster-management/config/types.ts @@ -89,7 +89,7 @@ export interface ClusterListItem { worker_pools: NodePoolListItem[]; k8s_volume_mounts?: VolumeMount[]; // Backend ClusterPublic carries this; admin-"All" namespace - // resolution falls back to the cluster's owner Org slug. + // resolution falls back to the cluster's owner Org name. owner_principal_id?: number; } diff --git a/src/pages/gpu-service/instances/index.tsx b/src/pages/gpu-service/instances/index.tsx index dc1c1a30..f9c3c254 100644 --- a/src/pages/gpu-service/instances/index.tsx +++ b/src/pages/gpu-service/instances/index.tsx @@ -41,7 +41,7 @@ const GPUService: React.FC = () => { const [currentCluster, setCurrentCluster] = useAtom(currentClusterAtom); const clusterID = currentCluster?.id; // In admin "All" view there's no Org context, so the helper falls - // back to the selected cluster's owner Org slug. + // back to the selected cluster's owner Org name. const namespace = getCurrentOrgNamespace(currentCluster?.owner_principal_id); const deleteInstance = useCallback( diff --git a/src/pages/gpu-service/instances/services/use-create-instance.ts b/src/pages/gpu-service/instances/services/use-create-instance.ts index efefffa8..312bcf13 100644 --- a/src/pages/gpu-service/instances/services/use-create-instance.ts +++ b/src/pages/gpu-service/instances/services/use-create-instance.ts @@ -15,7 +15,7 @@ export default function useCreateInstance() { const currentCluster = useAtomValue(currentClusterAtom); const clusterID = currentCluster?.id; // Admin "All" view has no Org context — fall back to the - // selected cluster's owner Org slug for the K8s namespace. + // selected cluster's owner Org name for the K8s namespace. const namespace = getCurrentOrgNamespace(currentCluster?.owner_principal_id); const fetchDetail = useCallback( diff --git a/src/pages/gpu-service/instances/services/use-update-instance.ts b/src/pages/gpu-service/instances/services/use-update-instance.ts index 00cdcfb9..672d82af 100644 --- a/src/pages/gpu-service/instances/services/use-update-instance.ts +++ b/src/pages/gpu-service/instances/services/use-update-instance.ts @@ -16,7 +16,7 @@ export default function useUpdateInstance() { const currentCluster = useAtomValue(currentClusterAtom); const clusterID = currentCluster?.id; // Admin "All" view has no Org context — fall back to the - // selected cluster's owner Org slug for the K8s namespace. + // selected cluster's owner Org name for the K8s namespace. const namespace = getCurrentOrgNamespace(currentCluster?.owner_principal_id); const fetchDetail = useCallback( diff --git a/src/pages/gpu-service/storage/index.tsx b/src/pages/gpu-service/storage/index.tsx index 1c116203..d99a3337 100644 --- a/src/pages/gpu-service/storage/index.tsx +++ b/src/pages/gpu-service/storage/index.tsx @@ -36,7 +36,7 @@ const GPUServiceStorage: React.FC = () => { const intl = useIntl(); const [currentCluster, setCurrentCluster] = useAtom(currentClusterAtom); const clusterID = currentCluster?.id; - // Admin "All" view falls back to the cluster's owner Org slug — + // Admin "All" view falls back to the cluster's owner Org name — // see :func:`getCurrentOrgNamespace`. const namespace = getCurrentOrgNamespace(currentCluster?.owner_principal_id); diff --git a/src/pages/gpu-service/storage/services/use-create-storage.ts b/src/pages/gpu-service/storage/services/use-create-storage.ts index 745e55ec..ff4c4759 100644 --- a/src/pages/gpu-service/storage/services/use-create-storage.ts +++ b/src/pages/gpu-service/storage/services/use-create-storage.ts @@ -15,7 +15,7 @@ export default function useCreateStorage() { const currentCluster = useAtomValue(currentClusterAtom); const clusterID = currentCluster?.id; // Admin "All" view has no Org context — fall back to the - // selected cluster's owner Org slug for the K8s namespace. + // selected cluster's owner Org name for the K8s namespace. const namespace = getCurrentOrgNamespace(currentCluster?.owner_principal_id); const fetchDetail = useCallback( diff --git a/src/pages/gpu-service/storage/services/use-query-storage.ts b/src/pages/gpu-service/storage/services/use-query-storage.ts index c49a868e..25d39105 100644 --- a/src/pages/gpu-service/storage/services/use-query-storage.ts +++ b/src/pages/gpu-service/storage/services/use-query-storage.ts @@ -10,7 +10,7 @@ export default function useQueryStorage() { const currentCluster = useAtomValue(currentClusterAtom); const clusterID = currentCluster?.id; // Admin "All" view has no Org context — fall back to the - // selected cluster's owner Org slug for the K8s namespace. + // selected cluster's owner Org name for the K8s namespace. const namespace = getCurrentOrgNamespace(currentCluster?.owner_principal_id); const fetchDetail = useCallback( diff --git a/src/pages/gpu-service/storage/services/use-update-storage.ts b/src/pages/gpu-service/storage/services/use-update-storage.ts index 47941f6d..e1b474be 100644 --- a/src/pages/gpu-service/storage/services/use-update-storage.ts +++ b/src/pages/gpu-service/storage/services/use-update-storage.ts @@ -16,7 +16,7 @@ export default function useUpdateStorage() { const currentCluster = useAtomValue(currentClusterAtom); const clusterID = currentCluster?.id; // Admin "All" view has no Org context — fall back to the - // selected cluster's owner Org slug for the K8s namespace. + // selected cluster's owner Org name for the K8s namespace. const namespace = getCurrentOrgNamespace(currentCluster?.owner_principal_id); const fetchDetail = useCallback(