Merge pull request #174 from a110605/align_gi

fix: align all memory / storage / quota units to Gi/Mi
This commit is contained in:
Andy Lee 2025-03-04 10:46:59 +08:00 committed by GitHub
commit 91d078068f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 88 additions and 58 deletions

View File

@ -1,3 +1,4 @@
// TODO: delete this not used variable
export const MemoryUnit = [{ export const MemoryUnit = [{
label: 'Mi', label: 'Mi',
value: 'Mi' value: 'Mi'

View File

@ -4,6 +4,7 @@ import { formatSi, exponentNeeded, UNITS } from '@shell/utils/units';
import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations'; import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
import { LONGHORN, METRIC } from '@shell/config/types'; import { LONGHORN, METRIC } from '@shell/config/types';
import { Banner } from '@components/Banner'; import { Banner } from '@components/Banner';
import { UNIT_SUFFIX } from '../../utils/unit';
import HarvesterCPUUsed from '../../formatters/HarvesterCPUUsed'; import HarvesterCPUUsed from '../../formatters/HarvesterCPUUsed';
import HarvesterMemoryUsed from '../../formatters/HarvesterMemoryUsed'; import HarvesterMemoryUsed from '../../formatters/HarvesterMemoryUsed';
import HarvesterStorageUsed from '../../formatters/HarvesterStorageUsed'; import HarvesterStorageUsed from '../../formatters/HarvesterStorageUsed';
@ -121,7 +122,7 @@ export default {
memoryUnits() { memoryUnits() {
const exponent = exponentNeeded(this.memoryTotal, 1024); const exponent = exponentNeeded(this.memoryTotal, 1024);
return `${ UNITS[exponent] }iB`; return `${ UNITS[exponent] }${ UNIT_SUFFIX }`;
}, },
nodeType() { nodeType() {

View File

@ -9,7 +9,7 @@ import ArrayListGrouped from '@shell/components/form/ArrayListGrouped';
import Loading from '@shell/components/Loading.vue'; import Loading from '@shell/components/Loading.vue';
import SortableTable from '@shell/components/SortableTable'; import SortableTable from '@shell/components/SortableTable';
import Banner from '@components/Banner/Banner.vue'; import Banner from '@components/Banner/Banner.vue';
import { UNIT_SUFFIX } from '../../utils/unit';
import metricPoller from '@shell/mixins/metric-poller'; import metricPoller from '@shell/mixins/metric-poller';
import { import {
METRIC, NODE, LONGHORN, POD, EVENT METRIC, NODE, LONGHORN, POD, EVENT
@ -178,7 +178,7 @@ export default {
minExponent: 3, minExponent: 3,
maxExponent: 3, maxExponent: 3,
maxPrecision: 2, maxPrecision: 2,
suffix: 'iB', suffix: UNIT_SUFFIX,
}; };
const longhornDisks = Object.keys(diskStatus).map((key) => { const longhornDisks = Object.keys(diskStatus).map((key) => {

View File

@ -5,6 +5,7 @@ import { Banner } from '@components/Banner';
import AsyncButton from '@shell/components/AsyncButton'; import AsyncButton from '@shell/components/AsyncButton';
import UnitInput from '@shell/components/form/UnitInput'; import UnitInput from '@shell/components/form/UnitInput';
import { exceptionToErrorsArray } from '@shell/utils/error'; import { exceptionToErrorsArray } from '@shell/utils/error';
import { GIBIBYTE } from '../utils/unit';
export default { export default {
name: 'HarvesterVMQuotaDialog', name: 'HarvesterVMQuotaDialog',
@ -29,6 +30,7 @@ export default {
data() { data() {
return { return {
GIBIBYTE,
totalSnapshotSize: '', totalSnapshotSize: '',
errors: [] errors: []
}; };
@ -44,7 +46,6 @@ export default {
}, },
methods: { methods: {
close() { close() {
this.totalSnapshotSize = ''; this.totalSnapshotSize = '';
this.$emit('close'); this.$emit('close');
@ -92,7 +93,7 @@ export default {
:input-exponent="3" :input-exponent="3"
:increment="1024" :increment="1024"
:output-modifier="true" :output-modifier="true"
suffix="GiB" :suffix="GIBIBYTE"
class="mb-20" class="mb-20"
/> />
</template> </template>

View File

@ -20,7 +20,7 @@ import Loading from '@shell/components/Loading.vue';
import MessageLink from '@shell/components/MessageLink'; import MessageLink from '@shell/components/MessageLink';
import { ADD_ONS } from '@pkg/harvester/config/harvester-map'; import { ADD_ONS } from '@pkg/harvester/config/harvester-map';
import { PRODUCT_NAME as HARVESTER_PRODUCT } from '@pkg/harvester/config/harvester'; import { PRODUCT_NAME as HARVESTER_PRODUCT } from '@pkg/harvester/config/harvester';
import { UNIT_SUFFIX } from '../../utils/unit';
import { _EDIT } from '@shell/config/query-params'; import { _EDIT } from '@shell/config/query-params';
import { sortBy } from '@shell/utils/sort'; import { sortBy } from '@shell/utils/sort';
import { Banner } from '@components/Banner'; import { Banner } from '@components/Banner';
@ -185,7 +185,7 @@ export default {
minExponent: 3, minExponent: 3,
maxExponent: 3, maxExponent: 3,
maxPrecision: 2, maxPrecision: 2,
suffix: 'iB', suffix: UNIT_SUFFIX,
}; };
const longhornDisks = Object.keys(diskStatus).map((key) => { const longhornDisks = Object.keys(diskStatus).map((key) => {
@ -457,7 +457,7 @@ export default {
const devPath = d.spec?.devPath; const devPath = d.spec?.devPath;
const deviceType = d.status?.deviceStatus?.details?.deviceType; const deviceType = d.status?.deviceStatus?.details?.deviceType;
const sizeBytes = d.status?.deviceStatus?.capacity?.sizeBytes; const sizeBytes = d.status?.deviceStatus?.capacity?.sizeBytes;
const size = formatSi(sizeBytes, { increment: 1024 }); const size = formatSi(sizeBytes, { increment: 1024, suffix: UNIT_SUFFIX });
const parentDevice = d.status?.deviceStatus?.parentDevice; const parentDevice = d.status?.deviceStatus?.parentDevice;
const isChildAdded = this.newDisks.find((newDisk) => newDisk.blockDevice?.status?.deviceStatus?.parentDevice === devPath); const isChildAdded = this.newDisks.find((newDisk) => newDisk.blockDevice?.status?.deviceStatus?.parentDevice === devPath);
const name = d.displayName; const name = d.displayName;

View File

@ -21,6 +21,7 @@ import { InterfaceOption, VOLUME_DATA_SOURCE_KIND } from '../config/harvester-ma
import { HCI, VOLUME_SNAPSHOT } from '../types'; import { HCI, VOLUME_SNAPSHOT } from '../types';
import { LVM_DRIVER } from '../models/harvester/storage.k8s.io.storageclass'; import { LVM_DRIVER } from '../models/harvester/storage.k8s.io.storageclass';
import { DATA_ENGINE_V2 } from '../models/harvester/persistentvolumeclaim'; import { DATA_ENGINE_V2 } from '../models/harvester/persistentvolumeclaim';
import { GIBIBYTE } from '../utils/unit';
export default { export default {
name: 'HarvesterVolume', name: 'HarvesterVolume',
@ -86,6 +87,7 @@ export default {
imageId, imageId,
snapshots: [], snapshots: [],
images: [], images: [],
GIBIBYTE
}; };
}, },
@ -288,7 +290,7 @@ export default {
const imageSize = Math.max(imageResource?.status?.size, imageResource?.status?.virtualSize); const imageSize = Math.max(imageResource?.status?.size, imageResource?.status?.virtualSize);
if (imageSize) { if (imageSize) {
this.storage = `${ Math.ceil(imageSize / 1024 / 1024 / 1024) }Gi`; this.storage = `${ Math.ceil(imageSize / 1024 / 1024 / 1024) }${ GIBIBYTE }`;
} }
} }
this.update(); this.update();
@ -377,6 +379,7 @@ export default {
:disabled="value?.isLonghornV2 && isEdit" :disabled="value?.isLonghornV2 && isEdit"
required required
class="mb-20" class="mb-20"
:suffix="GIBIBYTE"
@update:value="update" @update:value="update"
/> />

View File

@ -1,6 +1,7 @@
<script> <script>
import UnitInput from '@shell/components/form/UnitInput'; import UnitInput from '@shell/components/form/UnitInput';
import InputOrDisplay from '@shell/components/InputOrDisplay'; import InputOrDisplay from '@shell/components/InputOrDisplay';
import { GIBIBYTE } from '../../utils/unit';
export default { export default {
name: 'HarvesterEditCpuMemory', name: 'HarvesterEditCpuMemory',
@ -30,6 +31,7 @@ export default {
data() { data() {
return { return {
GIBIBYTE,
localCpu: this.cpu, localCpu: this.cpu,
localMemory: this.memory localMemory: this.memory
}; };
@ -63,7 +65,7 @@ export default {
if (String(this.localMemory).includes('Gi')) { if (String(this.localMemory).includes('Gi')) {
memory = this.localMemory; memory = this.localMemory;
} else { } else {
memory = `${ this.localMemory }Gi`; memory = `${ this.localMemory }${ GIBIBYTE }`;
} }
if (memory.includes('null')) { if (memory.includes('null')) {
memory = null; memory = null;
@ -113,6 +115,7 @@ export default {
:output-modifier="true" :output-modifier="true"
:disabled="disabled" :disabled="disabled"
required required
:suffix="GIBIBYTE"
class="mb-20" class="mb-20"
@update:value="change" @update:value="change"
/> />

View File

@ -1,6 +1,6 @@
<script> <script>
import UnitInput from '@shell/components/form/UnitInput'; import UnitInput from '@shell/components/form/UnitInput';
import { MEBIBYTE } from '../../utils/unit';
export default { export default {
name: 'HarvesterReserved', name: 'HarvesterReserved',
@ -20,7 +20,7 @@ export default {
}, },
data() { data() {
return { memory: this.reservedMemory }; return { MEBIBYTE, memory: this.reservedMemory };
}, },
watch: { watch: {
@ -47,6 +47,7 @@ export default {
:input-exponent="2" :input-exponent="2"
:increment="1024" :increment="1024"
:output-modifier="true" :output-modifier="true"
:suffix="MEBIBYTE"
@update:value="change" @update:value="change"
/> />
</template> </template>

View File

@ -11,6 +11,7 @@ import { _CREATE } from '@shell/config/query-params';
import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations'; import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
import { HCI } from '../../../../types'; import { HCI } from '../../../../types';
import { VOLUME_TYPE, InterfaceOption } from '../../../../config/harvester-map'; import { VOLUME_TYPE, InterfaceOption } from '../../../../config/harvester-map';
import { GIBIBYTE } from '../../../../utils/unit';
export default { export default {
name: 'HarvesterEditExisting', name: 'HarvesterEditExisting',
@ -59,6 +60,7 @@ export default {
} }
return { return {
GIBIBYTE,
VOLUME_TYPE, VOLUME_TYPE,
InterfaceOption, InterfaceOption,
loading: false, loading: false,
@ -254,6 +256,7 @@ export default {
:label="t('harvester.fields.size')" :label="t('harvester.fields.size')"
:mode="mode" :mode="mode"
:disabled="true" :disabled="true"
:suffix="GIBIBYTE"
@update:value="update" @update:value="update"
/> />
</InputOrDisplay> </InputOrDisplay>

View File

@ -12,6 +12,7 @@ import { VOLUME_TYPE, InterfaceOption } from '../../../../config/harvester-map';
import { _VIEW } from '@shell/config/query-params'; import { _VIEW } from '@shell/config/query-params';
import LabelValue from '@shell/components/LabelValue'; import LabelValue from '@shell/components/LabelValue';
import { ucFirst } from '@shell/utils/string'; import { ucFirst } from '@shell/utils/string';
import { GIBIBYTE } from '../../../../utils/unit';
export default { export default {
name: 'HarvesterEditVMImage', name: 'HarvesterEditVMImage',
@ -67,6 +68,7 @@ export default {
data() { data() {
return { return {
GIBIBYTE,
VOLUME_TYPE, VOLUME_TYPE,
InterfaceOption, InterfaceOption,
loading: false, loading: false,
@ -129,13 +131,17 @@ export default {
}, },
imageVirtualSize() { imageVirtualSize() {
return this.selectedImage?.virtualSize; if (this.selectedImage?.virtualSize) {
return this.selectedImage.virtualSize.replace(' ', '');
}
return '0';
}, },
diskSize() { diskSize() {
const size = this.value?.size || '0'; const size = this.value?.size || '0';
return `${ size.replace('Gi', '') } GB`; return size;
}, },
imageVirtualSizeInByte() { imageVirtualSizeInByte() {
@ -183,7 +189,7 @@ export default {
minExponent: 3, minExponent: 3,
}); });
this.value.size = `${ formatSize }Gi`; this.value.size = `${ formatSize }${ GIBIBYTE }`;
} }
}, },
deep: true, deep: true,
@ -225,7 +231,7 @@ export default {
if (!isIsoImage) { if (!isIsoImage) {
imageSizeGiB = Math.max(imageSizeGiB, 10); imageSizeGiB = Math.max(imageSizeGiB, 10);
} }
this.value['size'] = `${ imageSizeGiB }Gi`; this.value['size'] = `${ imageSizeGiB }${ GIBIBYTE }`;
} }
this.update(); this.update();
@ -332,7 +338,7 @@ export default {
:mode="mode" :mode="mode"
:required="validateRequired" :required="validateRequired"
:disable="isLonghornV2" :disable="isLonghornV2"
suffix="GiB" :suffix="GIBIBYTE"
@update:value="update" @update:value="update"
/> />
</InputOrDisplay> </InputOrDisplay>

View File

@ -12,6 +12,7 @@ import LabelValue from '@shell/components/LabelValue';
import { ucFirst } from '@shell/utils/string'; import { ucFirst } from '@shell/utils/string';
import { LVM_DRIVER } from '../../../../models/harvester/storage.k8s.io.storageclass'; import { LVM_DRIVER } from '../../../../models/harvester/storage.k8s.io.storageclass';
import { DATA_ENGINE_V2 } from '../../../../models/harvester/persistentvolumeclaim'; import { DATA_ENGINE_V2 } from '../../../../models/harvester/persistentvolumeclaim';
import { GIBIBYTE } from '../../../../utils/unit';
export default { export default {
name: 'HarvesterEditVolume', name: 'HarvesterEditVolume',
@ -58,6 +59,7 @@ export default {
data() { data() {
return { return {
GIBIBYTE,
VOLUME_TYPE, VOLUME_TYPE,
InterfaceOption, InterfaceOption,
loading: false, loading: false,
@ -140,7 +142,7 @@ export default {
minExponent: 3, minExponent: 3,
}); });
this.value.size = `${ formatSize }Gi`; this.value.size = `${ formatSize }${ GIBIBYTE }`;
} }
}, },
deep: true, deep: true,
@ -258,6 +260,7 @@ export default {
:required="validateRequired" :required="validateRequired"
:label="t('harvester.fields.size')" :label="t('harvester.fields.size')"
:disabled="isLonghornV2" :disabled="isLonghornV2"
:suffix="GIBIBYTE"
@update:value="update" @update:value="update"
/> />
</InputOrDisplay> </InputOrDisplay>

View File

@ -2,7 +2,7 @@
import ConsumptionGauge from '@shell/components/ConsumptionGauge'; import ConsumptionGauge from '@shell/components/ConsumptionGauge';
import { METRIC, NODE } from '@shell/config/types'; import { METRIC, NODE } from '@shell/config/types';
import { formatSi, exponentNeeded, UNITS, parseSi } from '@shell/utils/units'; import { formatSi, exponentNeeded, UNITS, parseSi } from '@shell/utils/units';
import { UNIT_SUFFIX } from '../utils/unit';
export default { export default {
name: 'HarvesterMemoryUsed', name: 'HarvesterMemoryUsed',
components: { ConsumptionGauge }, components: { ConsumptionGauge },
@ -51,7 +51,7 @@ export default {
memoryUnits() { memoryUnits() {
const exponent = exponentNeeded(this.memoryTotal, 1024); const exponent = exponentNeeded(this.memoryTotal, 1024);
return `${ UNITS[exponent] }iB`; return `${ UNITS[exponent] }${ UNIT_SUFFIX }`;
}, },
node() { node() {

View File

@ -2,6 +2,7 @@
import ConsumptionGauge from '@shell/components/ConsumptionGauge'; import ConsumptionGauge from '@shell/components/ConsumptionGauge';
import { LONGHORN } from '@shell/config/types'; import { LONGHORN } from '@shell/config/types';
import { formatSi, exponentNeeded, UNITS } from '@shell/utils/units'; import { formatSi, exponentNeeded, UNITS } from '@shell/utils/units';
import { UNIT_SUFFIX } from '../utils/unit';
export default { export default {
name: 'HarvesterStorageUsed', name: 'HarvesterStorageUsed',
@ -75,13 +76,13 @@ export default {
allocatedUnits() { allocatedUnits() {
const exponent = exponentNeeded(this.storageStats.total, 1024); const exponent = exponentNeeded(this.storageStats.total, 1024);
return `${ UNITS[exponent] }iB`; return `${ UNITS[exponent] }${ UNIT_SUFFIX }`;
}, },
usedUnits() { usedUnits() {
const exponent = exponentNeeded(this.storageStats.maximum, 1024); const exponent = exponentNeeded(this.storageStats.maximum, 1024);
return `${ UNITS[exponent] }iB`; return `${ UNITS[exponent] }${ UNIT_SUFFIX }`;
}, },
formatUsed() { formatUsed() {

View File

@ -8,9 +8,7 @@ import Banner from '@components/Banner/Banner.vue';
import MessageLink from '@shell/components/MessageLink'; import MessageLink from '@shell/components/MessageLink';
import SortableTable from '@shell/components/SortableTable'; import SortableTable from '@shell/components/SortableTable';
import { allHash, setPromiseResult } from '@shell/utils/promise'; import { allHash, setPromiseResult } from '@shell/utils/promise';
import { import { parseSi, formatSi, exponentNeeded, UNITS } from '@shell/utils/units';
parseSi, formatSi, exponentNeeded, UNITS, createMemoryValues
} from '@shell/utils/units';
import { REASON } from '@shell/config/table-headers'; import { REASON } from '@shell/config/table-headers';
import { import {
EVENT, METRIC, NODE, SERVICE, PVC, LONGHORN, POD, COUNT, NETWORK_ATTACHMENT EVENT, METRIC, NODE, SERVICE, PVC, LONGHORN, POD, COUNT, NETWORK_ATTACHMENT
@ -27,22 +25,21 @@ import { isEmpty } from '@shell/utils/object';
import { HCI } from '../types'; import { HCI } from '../types';
import HarvesterUpgrade from '../components/HarvesterUpgrade'; import HarvesterUpgrade from '../components/HarvesterUpgrade';
import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../config/harvester'; import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../config/harvester';
import { UNIT_SUFFIX } from '../utils/unit';
dayjs.extend(utc); dayjs.extend(utc);
dayjs.extend(minMax); dayjs.extend(minMax);
const PARSE_RULES = { const PARSE_RULES = {
memory: { format: {
format: { addSuffix: true,
addSuffix: true, firstSuffix: UNIT_SUFFIX,
firstSuffix: 'B', increment: 1024,
increment: 1024, maxExponent: 99,
maxExponent: 99, maxPrecision: 2,
maxPrecision: 2, minExponent: 0,
minExponent: 0, startingExponent: 0,
startingExponent: 0, suffix: UNIT_SUFFIX,
suffix: 'iB',
}
} }
}; };
@ -402,13 +399,13 @@ export default {
storageUsed() { storageUsed() {
const stats = this.storageStats; const stats = this.storageStats;
return this.createMemoryValues(stats.maximum, stats.used); return this.createDisplayValues(stats.maximum, stats.used);
}, },
storageAllocated() { storageAllocated() {
const stats = this.storageStats; const stats = this.storageStats;
return this.createMemoryValues(stats.total, stats.scheduled); return this.createDisplayValues(stats.total, stats.scheduled);
}, },
vmEvents() { vmEvents() {
@ -454,7 +451,7 @@ export default {
return total + node.memoryReserved; return total + node.memoryReserved;
}, 0); }, 0);
return createMemoryValues(this.memoryTotal, useful); return this.createDisplayValues(this.memoryTotal, useful);
}, },
availableNodes() { availableNodes() {
@ -494,7 +491,7 @@ export default {
}, },
ramUsed() { ramUsed() {
return createMemoryValues(this.memoryTotal, this.metricAggregations?.memory); return this.createDisplayValues(this.memoryTotal, this.metricAggregations?.memory);
}, },
hasMetricNodeSchema() { hasMetricNodeSchema() {
@ -516,10 +513,12 @@ export default {
}, },
methods: { methods: {
createMemoryValues(total, useful) { createDisplayValues(total, useful) {
const parsedTotal = parseSi((total || '0').toString()); const parsedTotal = parseSi((total || '0').toString());
const parsedUseful = parseSi((useful || '0').toString()); const parsedUseful = parseSi((useful || '0').toString());
const format = this.createMemoryFormat(parsedTotal); const format = this.createFormat(parsedTotal);
const formattedTotal = formatSi(parsedTotal, format); const formattedTotal = formatSi(parsedTotal, format);
let formattedUseful = formatSi(parsedUseful, { let formattedUseful = formatSi(parsedUseful, {
...format, ...format,
@ -538,24 +537,24 @@ export default {
useful: Number(parsedUseful), useful: Number(parsedUseful),
formattedTotal, formattedTotal,
formattedUseful, formattedUseful,
units: this.createMemoryUnits(parsedTotal), units: this.createUnits(parsedTotal),
}; };
}, },
createMemoryFormat(n) { createFormat(n) {
const exponent = exponentNeeded(n, PARSE_RULES.memory.format.increment); const exponent = exponentNeeded(n, PARSE_RULES.format.increment);
return { return {
...PARSE_RULES.memory.format, ...PARSE_RULES.format,
maxExponent: exponent, maxExponent: exponent,
minExponent: exponent, minExponent: exponent,
}; };
}, },
createMemoryUnits(n) { createUnits(n) {
const exponent = exponentNeeded(n, PARSE_RULES.memory.format.increment); const exponent = exponentNeeded(n, PARSE_RULES.format.increment);
return `${ UNITS[exponent] }${ PARSE_RULES.memory.format.suffix }`; return `${ UNITS[exponent] }${ PARSE_RULES.format.suffix }`;
}, },
async fetchClusterResources(type, opt = {}, store) { async fetchClusterResources(type, opt = {}, store) {

View File

@ -25,6 +25,7 @@ import { HCI_SETTING } from '../../config/settings';
import { HCI } from '../../types'; import { HCI } from '../../types';
import { parseVolumeClaimTemplates } from '../../utils/vm'; import { parseVolumeClaimTemplates } from '../../utils/vm';
import impl, { QGA_JSON, USB_TABLET } from './impl'; import impl, { QGA_JSON, USB_TABLET } from './impl';
import { GIBIBYTE } from '../../utils/unit';
const LONGHORN_V2_DATA_ENGINE = 'longhorn-system/v2-data-engine'; const LONGHORN_V2_DATA_ENGINE = 'longhorn-system/v2-data-engine';
@ -448,7 +449,7 @@ export default {
if (!isIsoImage) { if (!isIsoImage) {
imageSizeGiB = Math.max(imageSizeGiB, 10); imageSizeGiB = Math.max(imageSizeGiB, 10);
} }
size = `${ imageSizeGiB }Gi`; size = `${ imageSizeGiB }${ GIBIBYTE }`;
} }
out.push({ out.push({
@ -558,7 +559,7 @@ export default {
volumeName, volumeName,
container, container,
accessMode, accessMode,
size: `${ formatSize }Gi`, size: `${ formatSize }${ GIBIBYTE }`,
volumeMode: volumeMode || this.customVolumeMode, volumeMode: volumeMode || this.customVolumeMode,
image, image,
type, type,
@ -973,7 +974,7 @@ export default {
parseVolumeClaimTemplate(R, dataVolumeName) { parseVolumeClaimTemplate(R, dataVolumeName) {
if (!String(R.size).includes('Gi') && R.size) { if (!String(R.size).includes('Gi') && R.size) {
R.size = `${ R.size }Gi`; R.size = `${ R.size }${ GIBIBYTE }`;
} }
const out = { const out = {

View File

@ -12,6 +12,7 @@ import { HCI } from '../types';
import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../config/harvester'; import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../config/harvester';
import HarvesterResource from './harvester'; import HarvesterResource from './harvester';
import { CSI_SECRETS } from '@pkg/harvester/config/harvester-map'; import { CSI_SECRETS } from '@pkg/harvester/config/harvester-map';
import { UNIT_SUFFIX } from '../utils/unit';
const { const {
CSI_PROVISIONER_SECRET_NAME, CSI_PROVISIONER_SECRET_NAME,
@ -243,8 +244,8 @@ export default class HciVmImage extends HarvesterResource {
return formatSi(size, { return formatSi(size, {
increment: 1024, increment: 1024,
maxPrecision: 2, maxPrecision: 2,
suffix: 'B', suffix: UNIT_SUFFIX,
firstSuffix: 'B', firstSuffix: UNIT_SUFFIX,
}); });
} }
@ -258,8 +259,8 @@ export default class HciVmImage extends HarvesterResource {
return formatSi(virtualSize, { return formatSi(virtualSize, {
increment: 1024, increment: 1024,
maxPrecision: 2, maxPrecision: 2,
suffix: 'B', suffix: UNIT_SUFFIX,
firstSuffix: 'B', firstSuffix: UNIT_SUFFIX,
}); });
} }

View File

@ -0,0 +1,3 @@
export const UNIT_SUFFIX = 'i';
export const GIBIBYTE = 'Gi';
export const MEBIBYTE = 'Mi';

View File

@ -2,6 +2,7 @@ import { PVC } from '@shell/config/types';
import { isValidMac, isValidDNSLabelName } from '@pkg/utils/regular'; import { isValidMac, isValidDNSLabelName } from '@pkg/utils/regular';
import { SOURCE_TYPE } from '@pkg/config/harvester-map'; import { SOURCE_TYPE } from '@pkg/config/harvester-map';
import { parseVolumeClaimTemplates } from '@pkg/utils/vm'; import { parseVolumeClaimTemplates } from '@pkg/utils/vm';
import { GIBIBYTE } from '../utils/unit';
const maxNameLength = 63; const maxNameLength = 63;
@ -88,7 +89,7 @@ export function vmDisks(spec, getters, errors, validatorArgs, displayKey, value)
} }
if (typeValue?.spec?.resources?.requests?.storage && !/^([0-9][0-9]{0,8})[a-zA-Z]+$/.test(typeValue?.spec?.resources?.requests?.storage)) { if (typeValue?.spec?.resources?.requests?.storage && !/^([0-9][0-9]{0,8})[a-zA-Z]+$/.test(typeValue?.spec?.resources?.requests?.storage)) {
const message = getters['i18n/t']('harvester.validation.generic.maximumSize', { max: '999999999 GiB' }); const message = getters['i18n/t']('harvester.validation.generic.maximumSize', { max: `999999999 ${ GIBIBYTE }` });
errors.push(getters['i18n/t']('harvester.validation.generic.tabError', { prefix, message })); errors.push(getters['i18n/t']('harvester.validation.generic.tabError', { prefix, message }));
} }

View File

@ -1,3 +1,5 @@
import { GIBIBYTE } from '../utils/unit';
export function volumeSize(size, getters, errors, validatorArgs, displayKey, value) { export function volumeSize(size, getters, errors, validatorArgs, displayKey, value) {
if (!size) { if (!size) {
const key = getters['i18n/t']('harvester.volume.size'); const key = getters['i18n/t']('harvester.volume.size');
@ -6,7 +8,7 @@ export function volumeSize(size, getters, errors, validatorArgs, displayKey, val
} }
if (size && !/^([0-9][0-9]{0,8})[a-zA-Z]+$/.test(size)) { if (size && !/^([0-9][0-9]{0,8})[a-zA-Z]+$/.test(size)) {
const message = getters['i18n/t']('harvester.validation.generic.maximumSize', { max: '999999999 GiB' }); const message = getters['i18n/t']('harvester.validation.generic.maximumSize', { max: `999999999 ${ GIBIBYTE }` });
errors.push(message); errors.push(message);
} }