mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-29 01:08:56 +01:00
The PBS host physical disks change pointed the Proxmox page's forced platform filter at the proxmox-all aggregate but only taught the storage source matcher its prefix semantics. The workloads matcher still compared it for equality against concrete guest scopes (proxmox-pve), so every VM and LXC failed the filter and the Proxmox overview rendered 'No Proxmox workloads' on every install (#1663). Resolve the aggregate in one canonical predicate, sourcePlatformScopeMatchesFilter, and use it from both the workloads and storage matchers.
172 lines
4.5 KiB
TypeScript
172 lines
4.5 KiB
TypeScript
import type { Storage } from '@/types/api';
|
|
import { getAllFilterOptionLabel } from '@/components/shared/filterOptionPresentation';
|
|
import {
|
|
getSourcePlatformLabel,
|
|
normalizeSourcePlatformKey,
|
|
sourcePlatformScopeMatchesFilter,
|
|
} from '@/utils/sourcePlatforms';
|
|
import { titleCaseDelimitedLabel } from '@/utils/textPresentation';
|
|
|
|
export type StorageSourceTone = 'slate' | 'orange' | 'indigo' | 'rose' | 'teal' | 'cyan' | 'blue';
|
|
|
|
export interface StorageSourceOption {
|
|
key: string;
|
|
label: string;
|
|
tone: StorageSourceTone;
|
|
}
|
|
|
|
const ALL_STORAGE_SOURCE_OPTION: StorageSourceOption = {
|
|
key: 'all',
|
|
label: getAllFilterOptionLabel('sources'),
|
|
tone: 'slate',
|
|
};
|
|
|
|
const STORAGE_SOURCE_TONES: Record<string, StorageSourceTone> = {
|
|
'proxmox-pve': 'orange',
|
|
'proxmox-pbs': 'indigo',
|
|
'proxmox-pmg': 'rose',
|
|
ceph: 'teal',
|
|
truenas: 'blue',
|
|
kubernetes: 'cyan',
|
|
};
|
|
|
|
const CEPH_TYPES = new Set(['ceph', 'cephfs', 'rbd']);
|
|
|
|
const PROXMOX_STORAGE_TYPES = new Set([
|
|
'dir',
|
|
'nfs',
|
|
'cifs',
|
|
'lvm',
|
|
'lvmthin',
|
|
'zfspool',
|
|
'zfs',
|
|
'iscsi',
|
|
'glusterfs',
|
|
'btrfs',
|
|
]);
|
|
|
|
const STORAGE_SOURCE_ORDER = [
|
|
'proxmox-pve',
|
|
'proxmox-pbs',
|
|
'ceph',
|
|
'truenas',
|
|
'kubernetes',
|
|
'proxmox-pmg',
|
|
];
|
|
|
|
const slugifySource = (value: string): string =>
|
|
value
|
|
.trim()
|
|
.toLowerCase()
|
|
.replace(/[^a-z0-9]+/g, '-')
|
|
.replace(/^-+|-+$/g, '');
|
|
|
|
export const normalizeStorageSourceKey = (value: string | null | undefined): string => {
|
|
const normalized = slugifySource(value || '');
|
|
const canonicalPlatform = normalizeSourcePlatformKey(normalized);
|
|
if (canonicalPlatform) return canonicalPlatform;
|
|
|
|
switch (normalized) {
|
|
case 'all':
|
|
return 'all';
|
|
case 'ceph':
|
|
case 'cephfs':
|
|
case 'rbd':
|
|
return 'ceph';
|
|
default:
|
|
return normalized;
|
|
}
|
|
};
|
|
|
|
export const storageSourceMatchesFilter = (
|
|
source: string | null | undefined,
|
|
filter: string | null | undefined,
|
|
): boolean => {
|
|
const sourceKey = normalizeStorageSourceKey(source);
|
|
const filterKey = normalizeStorageSourceKey(filter);
|
|
return sourcePlatformScopeMatchesFilter(sourceKey, filterKey);
|
|
};
|
|
|
|
export const resolveStorageSourceKey = (storage: Storage): string => {
|
|
// Prefer the explicit canonical platform tag when the storage adapter
|
|
// already declared it (TrueNAS, VMware, Hyper-V, etc. set
|
|
// `storage.platform` to the canonical platform key). Falling through to
|
|
// raw `storage.type` here would otherwise collapse a vSAN/NFS/VMFS
|
|
// datastore to its on-disk technology and miss every platform-scoped
|
|
// filter (`forcedSourceFilter=vmware-vsphere` against a vSAN row, etc.).
|
|
const platform = normalizeStorageSourceKey(storage.platform || '');
|
|
if (
|
|
platform === 'truenas' ||
|
|
platform === 'vmware-vsphere' ||
|
|
platform === 'proxmox-pbs' ||
|
|
platform === 'proxmox-pmg' ||
|
|
platform === 'kubernetes' ||
|
|
platform === 'microsoft-hyperv'
|
|
) {
|
|
return platform;
|
|
}
|
|
|
|
const type = normalizeStorageSourceKey(storage.type);
|
|
|
|
if (
|
|
type === 'proxmox-pbs' ||
|
|
type === 'ceph' ||
|
|
type === 'kubernetes' ||
|
|
type === 'proxmox-pmg'
|
|
) {
|
|
return type;
|
|
}
|
|
|
|
if (CEPH_TYPES.has(type)) {
|
|
return 'ceph';
|
|
}
|
|
|
|
if (PROXMOX_STORAGE_TYPES.has(type) || type === '' || type === 'storage') {
|
|
return 'proxmox-pve';
|
|
}
|
|
|
|
if (type.includes('k8s') || type.includes('kubernetes') || type.includes('csi')) {
|
|
return 'kubernetes';
|
|
}
|
|
|
|
return type || 'proxmox-pve';
|
|
};
|
|
|
|
export const getStorageSourceOption = (value: string | null | undefined): StorageSourceOption => {
|
|
const key = normalizeStorageSourceKey(value);
|
|
|
|
if (key === 'all') {
|
|
return ALL_STORAGE_SOURCE_OPTION;
|
|
}
|
|
|
|
return {
|
|
key,
|
|
label:
|
|
(key === 'ceph' ? 'Ceph' : getSourcePlatformLabel(key)) ||
|
|
titleCaseDelimitedLabel(key) ||
|
|
'Other',
|
|
tone: STORAGE_SOURCE_TONES[key] || 'slate',
|
|
};
|
|
};
|
|
|
|
export const orderStorageSourceKeys = (keys: Iterable<string>): string[] =>
|
|
Array.from(new Set(Array.from(keys).map((key) => normalizeStorageSourceKey(key)))).sort(
|
|
(a, b) => {
|
|
const indexA = STORAGE_SOURCE_ORDER.indexOf(a);
|
|
const indexB = STORAGE_SOURCE_ORDER.indexOf(b);
|
|
if (indexA !== -1 || indexB !== -1) {
|
|
if (indexA === -1) return 1;
|
|
if (indexB === -1) return -1;
|
|
return indexA - indexB;
|
|
}
|
|
return a.localeCompare(b);
|
|
},
|
|
);
|
|
|
|
export const buildStorageSourceOptionsFromKeys = (
|
|
keys: Iterable<string>,
|
|
): StorageSourceOption[] => {
|
|
const orderedKeys = orderStorageSourceKeys(keys).filter((key) => key !== 'all');
|
|
return [ALL_STORAGE_SOURCE_OPTION, ...orderedKeys.map((key) => getStorageSourceOption(key))];
|
|
};
|