Skip to content

Commit

Permalink
Fix Virtual Machines Volumes access mode rules
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
(cherry picked from commit 21cbfa6)
  • Loading branch information
torchiaf authored and a110605 committed Oct 1, 2024
1 parent a2b4c8b commit 5ed785c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { LabeledInput } from '@components/Form/LabeledInput';
import LabeledSelect from '@shell/components/form/LabeledSelect';
import ModalWithCard from '@shell/components/ModalWithCard';
import { PVC, STORAGE_CLASS } from '@shell/config/types';
import { PVC } from '@shell/config/types';
import { HCI } from '../../../types';
import { clone } from '@shell/utils/object';
import { removeObject } from '@shell/utils/array';
Expand Down Expand Up @@ -172,10 +172,7 @@ export default {
};
if (type === SOURCE_TYPE.NEW) {
const inStore = this.$store.getters['currentProduct'].inStore;
const defaultStorage = this.$store.getters[`${ inStore }/all`](STORAGE_CLASS).find( O => O.isDefault);
neu.storageClassName = defaultStorage?.metadata?.name || 'longhorn';
neu.storageClassName = this.defaultStorageClass?.metadata?.name || 'longhorn';
}
this.rows.push(neu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { VOLUME_TYPE, InterfaceOption } from '../../../../config/harvester-map';
import { _VIEW } from '@shell/config/query-params';
import LabelValue from '@shell/components/LabelValue';
import { ucFirst } from '@shell/utils/string';
import { LVM_DRIVER } from '../../../../models/harvester/storage.k8s.io.storageclass';
import { DATA_ENGINE_V2 } from '../../../../edit/harvesterhci.io.storage/index.vue';
export default {
name: 'HarvesterEditVolume',
Expand Down Expand Up @@ -85,23 +87,34 @@ export default {
return !this.value.newCreateId && this.isEdit && this.isVirtualType;
},
storageClassOptions() {
const storages = this.$store.getters[`harvester/all`](STORAGE_CLASS) || [];
storageClasses() {
return this.$store.getters[`harvester/all`](STORAGE_CLASS) || [];
},
const out = storages.filter(s => !s.parameters?.backingImage).map((s) => {
storageClassOptions() {
return this.storageClasses.filter(s => !s.parameters?.backingImage).map((s) => {
const label = s.isDefault ? `${ s.name } (${ this.t('generic.default') })` : s.name;
return {
label,
value: s.name,
};
}) || [];
return out;
},
},
watch: {
'value.storageClassName': {
immediate: true,
handler(neu) {
const storageClass = this.storageClasses.find(sc => sc.name === neu);
const provisioner = storageClass?.provisioner;
const engine = storageClass?.parameters?.dataEngine;
this.value.accessMode = provisioner === LVM_DRIVER || engine === DATA_ENGINE_V2 ? 'ReadWriteOnce' : 'ReadWriteMany';
}
},
'value.type'(neu) {
if (neu === 'cd-rom') {
this.$set(this.value, 'bus', 'sata');
Expand Down
14 changes: 12 additions & 2 deletions pkg/harvester/mixins/harvester-vm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations
import impl, { QGA_JSON, USB_TABLET } from './impl';
import { uniq } from '@shell/utils/array';
import { parseVolumeClaimTemplates } from '../../utils/vm';
import { LONGHORN_VERSION_V1, LONGHORN_VERSION_V2 } from '@shell/models/persistentvolume';

const LONGHORN_V2_DATA_ENGINE = 'longhorn-system/v2-data-engine';

export const MANAGEMENT_NETWORK = 'management Network';

Expand Down Expand Up @@ -100,6 +103,7 @@ export default {
vms: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.VM }),
secrets: this.$store.dispatch(`${ inStore }/findAll`, { type: SECRET }),
addons: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.ADD_ONS }),
longhornV2Engine: this.$store.dispatch(`${ inStore }/find`, { type: LONGHORN.SETTINGS, id: LONGHORN_V2_DATA_ENGINE }),
};

if (this.$store.getters[`${ inStore }/schemaFor`](NODE)) {
Expand Down Expand Up @@ -241,7 +245,7 @@ export default {
defaultStorageClass() {
const defaultStorage = this.$store.getters[`${ this.inStore }/all`](STORAGE_CLASS).find( O => O.isDefault);

return defaultStorage?.metadata?.name || 'longhorn';
return defaultStorage;
},

storageClassSetting() {
Expand All @@ -254,6 +258,12 @@ export default {
}
},

longhornSystemVersion() {
const v2DataEngine = this.$store.getters[`${ this.inStore }/byId`](LONGHORN.SETTINGS, LONGHORN_V2_DATA_ENGINE) || {};

return v2DataEngine.value === 'true' ? LONGHORN_VERSION_V2 : LONGHORN_VERSION_V1;
},

customVolumeMode() {
return this.storageClassSetting.volumeMode || 'Block';
},
Expand Down Expand Up @@ -445,7 +455,7 @@ export default {
id: randomStr(5),
source: SOURCE_TYPE.IMAGE,
name: 'disk-0',
accessMode: 'ReadWriteMany',
accessMode: this.longhornSystemVersion === LONGHORN_VERSION_V2 ? 'ReadWriteOnce' : 'ReadWriteMany',
bus,
volumeName: '',
size,
Expand Down

0 comments on commit 5ed785c

Please sign in to comment.