mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-11-22 00:27:38 +08:00
* perf: speed up the VM list with many VMs The VM list scanned whole store lists for every row and re-evaluated the same values per row on every render and sort. With several hundred VMs this blocked the browser on sorting and on every VM update. Performance: - look up launcher pods and migrations through shared indexes (namespace/name -> resource) instead of scanning per row; the indexes are computed per store list, so they stay in sync with in-place store updates - use the same migration lookup (getLatestMigration) in the VM model and on the VM detail page - look up PVCs, PVs, VMIs and restore backups by id - merge VMs and VMIs with a Set - evaluate the VM state once when sorting by state - check the unschedulable condition before the pod based state checks - cache feature flag results and per-schema/per-setting values that are the same for every row Bug fixes: - the launcher pod map was never rebuilt, because the store keeps the same array - pods, volumes and migrations of a VM with the same name in another namespace could be picked up The order of the volumes of a VM (vm.volumes) now follows the VM spec instead of the store order. Nothing depends on it. Measured in a synthetic setup, 100 rows per page, sorting by state (Chrome, dev build): - ~490 VMs, ~500 PVCs/PVs: 1.9 s -> 1.0 s - ~490 VMs, 600 PVs, 200 migrations: 6.0 s -> 0.7 s, main thread blocked during VM updates 78% -> 32% With few volumes the gain is much smaller (8-20%). Related to: https://github.com/harvester/harvester/issues/9513 Signed-off-by: Volker Theile <vtheile@suse.com> * fix: read VM data from the store of the resource instead of a fixed one The migrations of a VMI and the migration badge of the state column were read from the hardcoded `harvester` store. In the Rancher explorer (embedded and standalone) the data is loaded into the `cluster` store, so a running migration was shown neither in the VM state nor as badge. The VM model remembered the store of the current product in a module variable on first use and never updated it. The same model is used in the Harvester product (`harvester` store) and in the Rancher explorer (`cluster` store), and Rancher keeps the page loaded when going from the explorer of a Harvester cluster to Virtualization Management and into the Harvester product. The VM list then read the VMIs, launcher pods, volumes and restores from the wrong store, and running VMs were shown as Starting until the page was reloaded. Read the data from the store the resource lives in (`this.$getters`, in the formatter the store of the current product). In the Harvester product this is still the `harvester` store, so nothing changes there. Not covered: volume details like the lock icon of encrypted volumes. The explorer uses the generic Rancher PVC model, which does not know them, and settings based checks (feature flags, backup target) are not loaded there either. Related to: https://github.com/harvester/harvester/issues/11882 Signed-off-by: Volker Theile <vtheile@suse.com> --------- Signed-off-by: Volker Theile <vtheile@suse.com>
404 lines
11 KiB
JavaScript
404 lines
11 KiB
JavaScript
import { _CLONE } from '@shell/config/query-params';
|
|
import pick from 'lodash/pick';
|
|
import { PV, LONGHORN, STORAGE_CLASS, LONGHORN_DRIVER } from '@shell/config/types';
|
|
import { DESCRIPTION } from '@shell/config/labels-annotations';
|
|
import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
|
|
import { findBy } from '@shell/utils/array';
|
|
import { get, clone } from '@shell/utils/object';
|
|
import { colorForState } from '@shell/plugins/dashboard-store/resource-class';
|
|
import { HCI, VOLUME_SNAPSHOT } from '../../types';
|
|
import HarvesterResource from '../harvester';
|
|
import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../../config/harvester';
|
|
import { CDI_POPULATOR_KIND } from '../../config/types';
|
|
import { LVM_DRIVER } from './storage.k8s.io.storageclass';
|
|
|
|
const DEGRADED_ERRORS = ['replica scheduling failed', 'precheck new replica failed'];
|
|
|
|
export const DATA_ENGINE_V1 = 'v1';
|
|
export const DATA_ENGINE_V2 = 'v2';
|
|
|
|
export default class HciPv extends HarvesterResource {
|
|
applyDefaults(_, realMode) {
|
|
const accessModes = realMode === _CLONE ? this.spec.accessModes : [];
|
|
const storage =
|
|
realMode === _CLONE ? this.spec.resources.requests.storage : null;
|
|
const storageClassName =
|
|
realMode === _CLONE ? this.spec.storageClassName : '';
|
|
|
|
this['spec'] = {
|
|
accessModes,
|
|
storageClassName,
|
|
volumeName: '',
|
|
resources: { requests: { storage } }
|
|
};
|
|
}
|
|
|
|
get availableActions() {
|
|
let out = super._availableActions;
|
|
|
|
const clone = out.find((action) => action.action === 'goToClone');
|
|
|
|
if (clone) {
|
|
clone.action = 'goToCloneVolume';
|
|
}
|
|
|
|
const exportImageAction = {
|
|
action: 'exportImage',
|
|
enabled: this.hasAction('export') && !this.isEncrypted,
|
|
icon: 'icon icon-external-link',
|
|
label: this.t('harvester.action.exportImage')
|
|
};
|
|
const takeSnapshotAction = {
|
|
action: 'snapshot',
|
|
enabled: this.hasAction('snapshot'),
|
|
icon: 'icon icon-backup',
|
|
label: this.t('harvester.action.snapshot'),
|
|
};
|
|
|
|
if (this.thirdPartyStorageFeatureEnabled) { // v1.5.0
|
|
out = [
|
|
exportImageAction,
|
|
takeSnapshotAction,
|
|
...out
|
|
];
|
|
} else { // v1.4 / v1.3
|
|
if (!this.isLonghorn || !this.isLonghornV2) {
|
|
out = [
|
|
exportImageAction,
|
|
takeSnapshotAction,
|
|
...out
|
|
];
|
|
}
|
|
}
|
|
|
|
return [
|
|
{
|
|
action: 'cancelExpand',
|
|
enabled: this.hasAction('cancelExpand'),
|
|
icon: 'icon icon-backup',
|
|
label: this.t('harvester.action.cancelExpand')
|
|
},
|
|
{
|
|
action: 'dataMigration',
|
|
enabled: this.hasAction('dataMigration') && this.createPVCWithDataVolumeFeatureEnabled,
|
|
icon: 'icon icon-copy',
|
|
label: this.t('harvester.action.dataMigration')
|
|
},
|
|
...out
|
|
];
|
|
}
|
|
|
|
dataMigration(resources = this) {
|
|
this.$dispatch('promptModal', {
|
|
resources,
|
|
component: 'HarvesterDataMigrationDialog'
|
|
});
|
|
}
|
|
|
|
exportImage(resources = this) {
|
|
this.$dispatch('promptModal', {
|
|
resources,
|
|
component: 'HarvesterExportImageDialog'
|
|
});
|
|
}
|
|
|
|
cancelExpand(resources = this) {
|
|
this.doActionGrowl('cancelExpand', {});
|
|
}
|
|
|
|
snapshot(resources = this) {
|
|
this.$dispatch('promptModal', {
|
|
resources,
|
|
component: 'SnapshotDialog'
|
|
});
|
|
}
|
|
|
|
goToCloneVolume(resources = this) {
|
|
this.$dispatch('promptModal', {
|
|
resources,
|
|
component: 'VolumeCloneDialog'
|
|
});
|
|
}
|
|
|
|
cleanForNew() {
|
|
this.$dispatch(`cleanForNew`, this);
|
|
|
|
delete this.metadata.finalizers;
|
|
const keys = [HCI_ANNOTATIONS.IMAGE_ID, DESCRIPTION];
|
|
|
|
this.metadata.annotations = pick(this.metadata.annotations, keys);
|
|
}
|
|
|
|
get storageClass() {
|
|
const inStore = this.$rootGetters['currentProduct'].inStore;
|
|
|
|
return this.$rootGetters[`${ inStore }/all`](STORAGE_CLASS).find((sc) => sc.name === this.spec.storageClassName);
|
|
}
|
|
|
|
get canUpdate() {
|
|
return this.hasLink('update');
|
|
}
|
|
|
|
get stateDisplay() {
|
|
const volumeError = this.relatedPV?.metadata?.annotations?.[HCI_ANNOTATIONS.VOLUME_ERROR];
|
|
const degradedVolume = DEGRADED_ERRORS.includes(volumeError);
|
|
const status = this?.status?.phase === 'Bound' && !volumeError && this.isLonghornVolumeReady ? 'Ready' : 'Not Ready';
|
|
|
|
const conditions = this?.status?.conditions || [];
|
|
|
|
if (findBy(conditions, 'type', 'Resizing')?.status === 'True') {
|
|
return 'Resizing';
|
|
} else if (!!this.attachVM && !volumeError) {
|
|
return 'In-use';
|
|
} else if (degradedVolume) {
|
|
return 'Degraded';
|
|
} else {
|
|
return status;
|
|
}
|
|
}
|
|
|
|
// state is similar with stateDisplay, the reason we keep this property is the status of In-use should not be displayed on vm detail page
|
|
get state() {
|
|
const volumeError = this.relatedPV?.metadata?.annotations?.[HCI_ANNOTATIONS.VOLUME_ERROR];
|
|
const degradedVolume = DEGRADED_ERRORS.includes(volumeError);
|
|
let status = this?.status?.phase === 'Bound' && !volumeError ? 'Ready' : 'Not Ready';
|
|
|
|
const conditions = this?.status?.conditions || [];
|
|
|
|
if (degradedVolume) {
|
|
status = 'Degraded';
|
|
}
|
|
|
|
if (findBy(conditions, 'type', 'Resizing')?.status === 'True') {
|
|
status = 'Resizing';
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
get stateColor() {
|
|
const state = this.stateDisplay;
|
|
|
|
return colorForState(state);
|
|
}
|
|
|
|
get stateDescription() {
|
|
return (
|
|
super.stateDescription
|
|
);
|
|
}
|
|
|
|
get detailLocation() {
|
|
const detailLocation = clone(this._detailLocation);
|
|
|
|
detailLocation.params.resource = HCI.VOLUME;
|
|
|
|
return detailLocation;
|
|
}
|
|
|
|
get doneOverride() {
|
|
const detailLocation = clone(this._detailLocation);
|
|
|
|
delete detailLocation.params.namespace;
|
|
delete detailLocation.params.id;
|
|
detailLocation.params.resource = HCI.VOLUME;
|
|
detailLocation.name = `${ HARVESTER_PRODUCT }-c-cluster-resource`;
|
|
|
|
return detailLocation;
|
|
}
|
|
|
|
get parentNameOverride() {
|
|
return this.$rootGetters['i18n/t'](`typeLabel."${ HCI.VOLUME }"`, { count: 1 }).trim();
|
|
}
|
|
|
|
get parentLocationOverride() {
|
|
return this.doneOverride;
|
|
}
|
|
|
|
get phaseState() {
|
|
return this.status?.phase || 'N/A';
|
|
}
|
|
|
|
get attachVM() {
|
|
const allVMs = this.$rootGetters['harvester/all'](HCI.VM) || [];
|
|
|
|
const findAttachVM = (vm) => {
|
|
const attachVolumes = vm.spec.template?.spec?.volumes || [];
|
|
|
|
if (vm.namespace === this.namespace && attachVolumes.length > 0) {
|
|
return attachVolumes.find((vol) => vol.persistentVolumeClaim?.claimName === this.name);
|
|
}
|
|
|
|
return null;
|
|
};
|
|
|
|
return allVMs.find(findAttachVM);
|
|
}
|
|
|
|
get attachVMName() {
|
|
return this.attachVM?.nameDisplay || this.attachVM?.metadata?.name || '';
|
|
}
|
|
|
|
get isAvailable() {
|
|
const unAvailable = ['Resizing', 'Not Ready'];
|
|
|
|
return !unAvailable.includes(this.stateDisplay);
|
|
}
|
|
|
|
get volumeSort() {
|
|
const volume = this.spec?.resources?.requests?.storage || 0;
|
|
|
|
return parseInt(volume);
|
|
}
|
|
|
|
get isSystemResource() {
|
|
const systemNamespaces = this.$rootGetters['systemNamespaces'];
|
|
|
|
if (systemNamespaces.includes(this.metadata?.namespace)) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
get isEncrypted() {
|
|
return this.relatedPV?.spec?.csi?.volumeAttributes?.encrypted === 'true';
|
|
}
|
|
|
|
get longhornVolume() {
|
|
const inStore = this.$rootGetters['currentProduct'].inStore;
|
|
|
|
return this.$rootGetters[`${ inStore }/all`](LONGHORN.VOLUMES).find((v) => v.metadata?.name === this.spec?.volumeName);
|
|
}
|
|
|
|
get longhornEngine() {
|
|
const inStore = this.$rootGetters['currentProduct'].inStore;
|
|
|
|
return this.$rootGetters[`${ inStore }/all`](LONGHORN.ENGINES).find((v) => v.spec?.volumeName === this.spec?.volumeName);
|
|
}
|
|
|
|
// https://github.com/longhorn/longhorn-manager/blob/master/api/model.go#L1151
|
|
get isLonghornVolumeReady() {
|
|
let ready = true;
|
|
const longhornVolume = this.longhornVolume || {};
|
|
|
|
const scheduledCondition = (longhornVolume?.status?.conditions || []).find((c) => c.type === 'Scheduled' || c.type === 'scheduled') || {};
|
|
|
|
if ((longhornVolume?.spec?.nodeID === '' && longhornVolume?.status?.state !== 'detached') ||
|
|
(longhornVolume?.status?.state === 'detached' && scheduledCondition.status !== 'True') ||
|
|
longhornVolume?.status?.robustness === 'faulted' ||
|
|
longhornVolume?.status?.restoreRequired ||
|
|
longhornVolume?.status?.cloneStatus?.state === 'failed'
|
|
) {
|
|
ready = false;
|
|
}
|
|
|
|
return ready;
|
|
}
|
|
|
|
get relatedVolumeSnapshotCounts() {
|
|
const snapshots = this.$rootGetters['harvester/all'](VOLUME_SNAPSHOT);
|
|
|
|
return snapshots.filter((snapshot) => {
|
|
const volumeId = `${ snapshot.metadata?.namespace }/${ snapshot.spec?.source?.persistentVolumeClaimName }`;
|
|
const kind = snapshot.metadata?.ownerReferences?.[0]?.kind;
|
|
|
|
return volumeId === this.id && kind === 'PersistentVolumeClaim';
|
|
});
|
|
}
|
|
|
|
get originalSnapshot() {
|
|
if (this.spec?.dataSource) {
|
|
return this.$rootGetters['harvester/all'](VOLUME_SNAPSHOT).find((V) => V.metadata?.name === this.spec.dataSource.name);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
get source() {
|
|
const imageId = get(this, `metadata.annotations."${ HCI_ANNOTATIONS.IMAGE_ID }"`);
|
|
|
|
return imageId ? 'image' : 'data';
|
|
}
|
|
|
|
get warnDeletionMessage() {
|
|
return this.t('harvester.volume.promptRemove.tips');
|
|
}
|
|
|
|
get relatedPV() {
|
|
return this.$rootGetters['harvester/byId'](PV, this.spec?.volumeName);
|
|
}
|
|
|
|
get volumeProvider() {
|
|
return this.relatedPV?.spec.csi?.driver;
|
|
}
|
|
|
|
get dataEngine() {
|
|
return this.relatedPV?.spec.csi?.volumeAttributes?.dataEngine;
|
|
}
|
|
|
|
get isLvm() {
|
|
return this.volumeProvider === LVM_DRIVER;
|
|
}
|
|
|
|
get isLonghorn() {
|
|
return this.volumeProvider === LONGHORN_DRIVER;
|
|
}
|
|
|
|
get isLonghornV1() {
|
|
return this.isLonghorn && !this.isLonghornV2;
|
|
}
|
|
|
|
get isLonghornV2() {
|
|
return this.dataEngine === DATA_ENGINE_V2;
|
|
}
|
|
|
|
get isGoldenImageVolume() {
|
|
return this?.metadata?.annotations?.[HCI_ANNOTATIONS.GOLDEN_IMAGE] === 'true';
|
|
}
|
|
|
|
get isCDIPopulatorVolume() {
|
|
const kind = this?.metadata?.annotations?.[HCI_ANNOTATIONS.CDI_POPULATOR_KIND];
|
|
|
|
return kind === CDI_POPULATOR_KIND.VOLUME_IMPORT_SOURCE || kind === CDI_POPULATOR_KIND.VOLUME_CLONE_SOURCE;
|
|
}
|
|
|
|
get thirdPartyStorageFeatureEnabled() {
|
|
return this.$rootGetters['harvester-common/getFeatureEnabled']('thirdPartyStorage');
|
|
}
|
|
|
|
get createPVCWithDataVolumeFeatureEnabled() {
|
|
return this.$rootGetters['harvester-common/getFeatureEnabled']('createPVCWithDataVolume');
|
|
}
|
|
|
|
get resourceExternalLink() {
|
|
const host = window.location.host;
|
|
const { params } = this.currentRoute();
|
|
const volumeName = this.spec?.volumeName;
|
|
|
|
if (!this.isLonghorn) {
|
|
return null;
|
|
}
|
|
|
|
if (!volumeName) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
tipsKey: 'harvester.volume.externalLink.tips',
|
|
url: `https://${ host }/k8s/clusters/${ params.cluster }/api/v1/namespaces/longhorn-system/services/http:longhorn-frontend:80/proxy/#/volume/${ volumeName }`
|
|
};
|
|
}
|
|
|
|
get customValidationRules() {
|
|
return [
|
|
{
|
|
nullable: false,
|
|
path: 'spec.resources.requests.storage',
|
|
required: true,
|
|
validators: ['volumeSize']
|
|
},
|
|
];
|
|
}
|
|
}
|