mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-11-15 21:36:16 +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>
159 lines
3.8 KiB
Vue
159 lines
3.8 KiB
Vue
<script>
|
|
import { get } from '@shell/utils/object';
|
|
import { isIpv4 } from '@shell/utils/string';
|
|
import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
|
|
import CopyToClipboardText from '@shell/components/CopyToClipboardText';
|
|
import { HCI } from '../types';
|
|
import { MANAGEMENT_NETWORK } from '../mixins/harvester-vm';
|
|
import { OFF } from '../models/kubevirt.io.virtualmachine';
|
|
|
|
export default {
|
|
components: { CopyToClipboardText },
|
|
props: {
|
|
value: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
row: {
|
|
type: Object,
|
|
required: true
|
|
},
|
|
col: {
|
|
type: Object,
|
|
default: () => {}
|
|
}
|
|
},
|
|
|
|
data() {
|
|
return { inStore: 'harvester' };
|
|
},
|
|
|
|
created() {
|
|
const inStore = this.$store.getters['currentProduct'].inStore;
|
|
|
|
this.inStore = inStore;
|
|
},
|
|
|
|
computed: {
|
|
ips() {
|
|
if (this.staticAnnotationIP.length) {
|
|
return this.staticAnnotationIP;
|
|
}
|
|
|
|
if (this.vmiIp.length) {
|
|
return [...this.vmiIp, ...this.networkAnnotationIP]
|
|
.filter(Boolean)
|
|
.sort((a, b) => a.ip < b.ip ? -1 : 1);
|
|
}
|
|
|
|
return this.customAnnotationIP;
|
|
},
|
|
|
|
staticAnnotationIP() {
|
|
const annotations = this.row?.metadata?.annotations || {};
|
|
const staticIpPrefix = `${ HCI_ANNOTATIONS.STATIC_IP }/`;
|
|
|
|
return Object.entries(annotations)
|
|
.filter(([key, value]) => key.startsWith(staticIpPrefix) && !!value)
|
|
.map(([key, value]) => {
|
|
const nicName = key.slice(staticIpPrefix.length);
|
|
const ip = String(value).replace(/\/[\d\D]*/, '');
|
|
|
|
return {
|
|
ip,
|
|
name: nicName
|
|
};
|
|
})
|
|
.filter(({ ip }) => isIpv4(ip));
|
|
},
|
|
|
|
customAnnotationIP() {
|
|
const annotationIp = get(this.row, `metadata.annotations."${ HCI_ANNOTATIONS.CUSTOM_IP }"`);
|
|
|
|
if (annotationIp && isIpv4(annotationIp)) {
|
|
return [{
|
|
name: 'custom-ip', ip: annotationIp, isCustom: true
|
|
}];
|
|
}
|
|
|
|
return [];
|
|
},
|
|
|
|
networkAnnotationIP() {
|
|
if (this.row.actualState !== 'Running') { // TODO: Running
|
|
return [];
|
|
}
|
|
|
|
const annotationIp = get(this.row, `metadata.annotations."${ HCI_ANNOTATIONS.NETWORK_IPS }"`) || '[]';
|
|
|
|
// Obtain IP from VM annotation, remove the CIDR suffix number if CIDR Exist
|
|
try {
|
|
const out = JSON.parse(annotationIp);
|
|
|
|
return out.map( (ip) => ({
|
|
ip: ip.replace(/\/[\d\D]*/, ''),
|
|
name: ''
|
|
}));
|
|
} catch (e) {
|
|
return [];
|
|
}
|
|
},
|
|
|
|
vmiIp() {
|
|
const resource = this.$store.getters[`${ this.inStore }/byId`](HCI.VMI, this.value);
|
|
const networksName = this.row.networksName || [];
|
|
const vmiNetworks = resource?.spec?.networks || [];
|
|
|
|
return (resource?.status?.interfaces || []).filter((intf) => {
|
|
return isIpv4(intf.ipAddress) && networksName.includes(intf.name);
|
|
}).map((intf) => {
|
|
let name;
|
|
const network = vmiNetworks.find((network) => network.name === intf.name);
|
|
|
|
if (network && network.multus) {
|
|
name = network.multus.networkName;
|
|
} else if (network && network.pod) {
|
|
name = MANAGEMENT_NETWORK;
|
|
}
|
|
|
|
return {
|
|
ip: intf.ipAddress,
|
|
name
|
|
};
|
|
});
|
|
},
|
|
|
|
showIP() {
|
|
return this.row.stateDisplay !== OFF;
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div
|
|
v-if="showIP"
|
|
class="ip-list"
|
|
>
|
|
<div
|
|
v-for="{ ip, name, isCustom } in ips"
|
|
:key="`${ip}-${name}`"
|
|
class="ip-item"
|
|
>
|
|
<CopyToClipboardText
|
|
v-clean-tooltip="isCustom ? t('harvester.formatters.harvesterIpAddress.customIpTooltip') : name"
|
|
:text="ip"
|
|
:plain="isCustom"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style lang="scss" scoped>
|
|
.ip-list {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 6px;
|
|
}
|
|
</style>
|