Skip to content

Commit 9343813

Browse files
authored
Add volum mode options in create VM volume tab (#209)
* add volume mode option for non-longhorn volume Signed-off-by: Andy Lee <[email protected]> * fix default storage class in create VM page Signed-off-by: Andy Lee <[email protected]> --------- Signed-off-by: Andy Lee <[email protected]>
1 parent 2dff7b0 commit 9343813

File tree

3 files changed

+75
-12
lines changed

3 files changed

+75
-12
lines changed

pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/index.vue

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import UnitInput from '@shell/components/form/UnitInput';
77
import { LabeledInput } from '@components/Form/LabeledInput';
88
import LabeledSelect from '@shell/components/form/LabeledSelect';
99
import ModalWithCard from '@shell/components/ModalWithCard';
10-
11-
import { PVC } from '@shell/config/types';
10+
import { PVC, STORAGE_CLASS } from '@shell/config/types';
1211
import { clone } from '@shell/utils/object';
1312
import { ucFirst, randomStr } from '@shell/utils/string';
1413
import { removeObject } from '@shell/utils/array';
@@ -117,6 +116,12 @@ export default {
117116
return this.mode === _CREATE;
118117
},
119118
119+
defaultStorageClass() {
120+
const defaultStorage = this.$store.getters['harvester/all'](STORAGE_CLASS).find((sc) => sc.isDefault);
121+
122+
return defaultStorage;
123+
},
124+
120125
showVolumeTip() {
121126
const imageName = this.getImageDisplayName(this.rows[0]?.image);
122127

pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/volume.vue

+68-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ucFirst } from '@shell/utils/string';
1313
import { LVM_DRIVER } from '../../../../models/harvester/storage.k8s.io.storageclass';
1414
import { DATA_ENGINE_V2 } from '../../../../models/harvester/persistentvolumeclaim';
1515
import { GIBIBYTE } from '../../../../utils/unit';
16+
import { VOLUME_MODE } from '@pkg/harvester/config/types';
1617
1718
export default {
1819
name: 'HarvesterEditVolume',
@@ -71,6 +72,10 @@ export default {
7172
return this.$store.getters['harvester-common/getFeatureEnabled']('longhornV2LVMSupport');
7273
},
7374
75+
thirdPartyStorageClassEnabled() {
76+
return this.$store.getters['harvester-common/getFeatureEnabled']('thirdPartyStorage');
77+
},
78+
7479
encryptionValue() {
7580
return ucFirst(String(this.value.isEncrypted));
7681
},
@@ -91,6 +96,18 @@ export default {
9196
return allPVCs.find((P) => P.id === `${ this.namespace }/${ this.value.volumeName }`);
9297
},
9398
99+
showVolumeMode() {
100+
if (!this.thirdPartyStorageClassEnabled || !!this.value?.storageClassName === false) {
101+
return false;
102+
}
103+
104+
if (this.isLonghornStorageClass) {
105+
return false;
106+
}
107+
108+
return true;
109+
},
110+
94111
isDisabled() {
95112
return !this.value.newCreateId && this.isEdit && this.isVirtualType;
96113
},
@@ -112,14 +129,26 @@ export default {
112129
113130
isLonghornV2() {
114131
return this.value.pvc?.isLonghornV2 || this.value.pvc?.storageClass?.isLonghornV2;
115-
}
132+
},
133+
134+
isLonghornStorageClass() {
135+
const selectedSC = this.storageClasses.find((sc) => sc.name === this.value?.storageClassName) || {};
136+
137+
return selectedSC && selectedSC.isLonghorn;
138+
},
139+
140+
volumeModeOptions() {
141+
return Object.values(VOLUME_MODE);
142+
},
116143
},
117144
118145
watch: {
119146
'value.storageClassName': {
120147
immediate: true,
121148
handler(neu) {
122149
this.value.accessMode = this.getAccessMode(neu);
150+
this.value.volumeMode = this.getVolumeMode(neu, this.value.volumeMode);
151+
this.update();
123152
}
124153
},
125154
@@ -151,6 +180,20 @@ export default {
151180
},
152181
153182
methods: {
183+
getVolumeMode(storageClassName, originalVolumeMode) {
184+
if (!this.thirdPartyStorageClassEnabled) {
185+
return VOLUME_MODE.BLOCK;
186+
}
187+
const storageClass = this.storageClasses.find((sc) => sc.name === storageClassName);
188+
189+
// longhorn v1, v2 use block volumeMode
190+
if (storageClass && storageClass.isLonghorn) {
191+
return VOLUME_MODE.BLOCK;
192+
}
193+
194+
return originalVolumeMode;
195+
},
196+
154197
getAccessMode(storageClassName) {
155198
if (!this.longhornV2LVMSupport) {
156199
return 'ReadWriteMany';
@@ -286,6 +329,29 @@ export default {
286329
/>
287330
</InputOrDisplay>
288331
</div>
332+
<div
333+
v-if="showVolumeMode"
334+
data-testid="input-volume-mode"
335+
class="col span-6"
336+
>
337+
<InputOrDisplay
338+
:name="t('harvester.volume.volumeMode')"
339+
:value="value.volumeMode"
340+
:mode="mode"
341+
>
342+
<LabeledSelect
343+
v-model:value="value.volumeMode"
344+
:label="t('harvester.volume.volumeMode')"
345+
:mode="mode"
346+
:options="volumeModeOptions"
347+
:disabled="isEdit"
348+
required
349+
@update:value="update"
350+
/>
351+
</InputOrDisplay>
352+
</div>
353+
</div>
354+
<div class="row mb-20">
289355
<div
290356
v-if="value.volumeEncryptionFeatureEnabled && isView"
291357
class="col span-6"
@@ -295,11 +361,9 @@ export default {
295361
:value="encryptionValue"
296362
/>
297363
</div>
298-
</div>
299-
<div class="row mb-20">
300364
<div
301365
v-if="value.volumeBackups && isView"
302-
class="col span-3"
366+
class="col span-6"
303367
>
304368
<LabelValue
305369
:name="t('harvester.virtualMachine.volume.readyToUse')"

pkg/harvester/mixins/harvester-vm/index.js

-6
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,6 @@ export default {
245245
});
246246
},
247247

248-
defaultStorageClass() {
249-
const defaultStorage = this.$store.getters[`${ this.inStore }/all`](STORAGE_CLASS).find( (O) => O.isDefault);
250-
251-
return defaultStorage;
252-
},
253-
254248
storageClassSetting() {
255249
try {
256250
const storageClassValue = this.$store.getters[`${ this.inStore }/all`](HCI.SETTING).find( (O) => O.id === HCI_SETTING.DEFAULT_STORAGE_CLASS)?.value;

0 commit comments

Comments
 (0)