Skip to content

Commit

Permalink
Add new provisioner fields when saving new disks; Fix Storage class p…
Browse files Browse the repository at this point in the history
…rovisioner parameters

Signed-off-by: Francesco Torchia <[email protected]>
  • Loading branch information
torchiaf committed Sep 11, 2024
1 parent d0858f1 commit dedcf22
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 59 deletions.
71 changes: 51 additions & 20 deletions pkg/harvester/edit/harvesterhci.io.host/HarvesterDisk.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import HarvesterDisk from '../../mixins/harvester-disk';
import Tags from '../../components/DiskTags';
import { HCI } from '../../types';
import { LONGHORN_SYSTEM } from './index';
import { LONGHORN_DRIVER } from '@shell/models/persistentvolume';
import { LONGHORN_DRIVER, LONGHORN_VERSION_V1, LONGHORN_VERSION_V2 } from '@shell/models/persistentvolume';
import { LVM_DRIVER } from '@shell/models/storage.k8s.io.storageclass';
const LONGHORN_V2_DATA_ENGINE = 'longhorn-system/v2-data-engine';
Expand Down Expand Up @@ -43,6 +43,12 @@ export default {
type: Array,
default: () => [],
},
node: {
type: Object,
default: () => {
return {};
},
},
mode: {
type: String,
default: 'edit',
Expand All @@ -52,22 +58,11 @@ export default {
async fetch() {
const inStore = this.$store.getters['currentProduct'].inStore;
const hash = await allHash({
await allHash({
csiDrivers: this.$store.dispatch(`${ inStore }/findAll`, { type: CSI_DRIVER }),
longhornV2DataEngine: this.$store.dispatch(`${ inStore }/find`, { type: LONGHORN.SETTINGS, id: LONGHORN_V2_DATA_ENGINE }),
lvmVolumeGroups: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.LVM_VOLUME_GROUP }),
});
this.longhornVersion = hash.longhornV2DataEngine.value === 'true' ? 'v2' : 'v1';
},
data() {
return {
longhornVersion: 'v1',
provisioner: {
label: this.t(`harvester.storage.storageClass.${ LONGHORN_DRIVER }.label`, { version: 1 }),
value: LONGHORN_DRIVER,
}
};
},
computed: {
Expand All @@ -83,6 +78,13 @@ export default {
});
},
lvmVolumeGroups() {
const inStore = this.$store.getters['currentProduct'].inStore;
const lvmVolumeGroups = this.$store.getters[`${ inStore }/all`](HCI.LVM_VOLUME_GROUP) || [];
return lvmVolumeGroups.filter(group => group.spec.nodeName === this.node.name).map(g => g.spec.vgName);
},
targetDisk() {
return this.disks.find(disk => disk.name === this.value.name);
},
Expand Down Expand Up @@ -195,10 +197,25 @@ export default {
return this.blockDevice.isFormatting;
},
longhornVersion() {
const inStore = this.$store.getters['currentProduct'].inStore;
const v2DataEngine = this.$store.getters[`${ inStore }/byId`](LONGHORN.SETTINGS, LONGHORN_V2_DATA_ENGINE) || {};
return v2DataEngine.value === 'true' ? LONGHORN_VERSION_V2 : LONGHORN_VERSION_V1;
},
isLvm() {
return this.value.provisioner === LVM_DRIVER;
},
isLonghornV1() {
return this.value.provisioner === LONGHORN_DRIVER && this.longhornVersion === LONGHORN_VERSION_V1;
},
provisionersLabelKeys() {
return {
[LONGHORN_DRIVER]: `harvester.storage.storageClass.longhorn.${ this.longhornVersion }.label`,
[LVM_DRIVER]: 'harvester.storage.storageClass.lvm.label'
[LVM_DRIVER]: 'harvester.storage.storageClass.lvm.label'
};
},
},
Expand Down Expand Up @@ -297,16 +314,20 @@ export default {
<hr class="mt-10" />
</div>
<div class="row mt-10">
<div class="col span-6">
<div class="col span-12">
<LabeledInput
v-model="value.displayName"
:label="t('generic.name')"
:disabled="true"
/>
</div>
</div>
<div class="row mt-10">
<div class="col span-6">
<LabeledSelect
v-model="provisioner"
v-if="value.isNew"
v-model="value.provisioner"
:mode="mode"
label-key="harvester.host.disk.provisioner"
:localized-label="true"
Expand All @@ -315,9 +336,7 @@ export default {
@keydown.native.enter.prevent="()=>{}"
/>
</div>
</div>
<div v-if="(value.isNew && !isFormatted) || isCorrupted" class="row mt-10">
<div class="col span-6">
<div v-if="(value.isNew && isLonghornV1 && !isFormatted) || isCorrupted" class="col span-6">
<RadioGroup
v-model="value.forceFormatted"
:mode="mode"
Expand All @@ -339,6 +358,18 @@ export default {
</template>
</RadioGroup>
</div>
<div v-if="value.isNew && isLvm" class="col span-6">
<LabeledSelect
v-model="value.lvmVolumeGroup"
:mode="mode"
label-key="harvester.host.disk.lvmVolumeGroup"
:localized-label="true"
:searchable="true"
:options="lvmVolumeGroups"
:required="true"
@keydown.native.enter.prevent="()=>{}"
/>
</div>
</div>
</div>
</template>
Expand Down
76 changes: 47 additions & 29 deletions pkg/harvester/edit/harvesterhci.io.host/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import HarvesterDisk from './HarvesterDisk';
import HarvesterKsmtuned from './HarvesterKsmtuned';
import HarvesterSeeder from './HarvesterSeeder';
import Tags from '../../components/DiskTags';
import { LONGHORN_DRIVER, LONGHORN_VERSION_V1 } from '@shell/models/persistentvolume';
import { LVM_DRIVER } from '@shell/models/storage.k8s.io.storageclass';
import isEqual from 'lodash/isEqual';
export const LONGHORN_SYSTEM = 'longhorn-system';
Expand Down Expand Up @@ -86,13 +89,16 @@ export default {
const corrupted = d?.status?.deviceStatus?.fileSystem?.corrupted;
return {
isNew: true,
name: d?.metadata?.name,
originPath: d?.spec?.fileSystem?.mountPoint,
path: d?.spec?.fileSystem?.mountPoint,
blockDevice: d,
displayName: d?.displayName,
forceFormatted: corrupted ? true : d?.spec?.fileSystem?.forceFormatted || false,
isNew: true,
name: d?.metadata?.name,
originPath: d?.spec?.fileSystem?.mountPoint,
path: d?.spec?.fileSystem?.mountPoint,
blockDevice: d,
displayName: d?.displayName,
forceFormatted: corrupted ? true : d?.spec?.fileSystem?.forceFormatted || false,
provisioner: d?.spec?.provisioner?.lvm ? LVM_DRIVER : LONGHORN_DRIVER,
provisionerVersion: d?.spec?.provisioner?.longhorn?.engineVersion || LONGHORN_VERSION_V1, // todo get default from system version
lvmVolumeGroup: d?.spec?.provisioner?.lvm?.vgName,
};
});
Expand Down Expand Up @@ -176,16 +182,19 @@ export default {
return {
...diskStatus[key],
...diskSpec?.[key],
name: key,
isNew: false,
storageReserved: formatSi(diskSpec[key]?.storageReserved, formatOptions),
storageAvailable: formatSi(diskStatus[key]?.storageAvailable, formatOptions),
storageMaximum: formatSi(diskStatus[key]?.storageMaximum, formatOptions),
storageScheduled: formatSi(diskStatus[key]?.storageScheduled, formatOptions),
name: key,
isNew: false,
storageReserved: formatSi(diskSpec[key]?.storageReserved, formatOptions),
storageAvailable: formatSi(diskStatus[key]?.storageAvailable, formatOptions),
storageMaximum: formatSi(diskStatus[key]?.storageMaximum, formatOptions),
storageScheduled: formatSi(diskStatus[key]?.storageScheduled, formatOptions),
blockDevice,
displayName: blockDevice?.displayName || key,
forceFormatted: blockDevice?.spec?.fileSystem?.forceFormatted || false,
tags: diskSpec?.[key]?.tags || [],
displayName: blockDevice?.displayName || key,
forceFormatted: blockDevice?.spec?.fileSystem?.forceFormatted || false,
tags: diskSpec?.[key]?.tags || [],
provisioner: blockDevice?.spec?.provisioner?.lvm ? LVM_DRIVER : LONGHORN_DRIVER,
provisionerVersion: blockDevice?.spec?.provisioner?.longhorn?.engineVersion || LONGHORN_VERSION_V1, // todo get default from system version
lvmVolumeGroup: blockDevice?.spec?.provisioner?.lvm?.vgName,
};
});
Expand Down Expand Up @@ -312,15 +321,18 @@ export default {
this.newDisks.push({
name,
path: mountPoint,
allowScheduling: false,
evictionRequested: false,
storageReserved: 0,
isNew: true,
originPath: disk?.spec?.fileSystem?.mountPoint,
blockDevice: disk,
displayName: disk?.displayName,
path: mountPoint,
allowScheduling: false,
evictionRequested: false,
storageReserved: 0,
isNew: true,
originPath: disk?.spec?.fileSystem?.mountPoint,
blockDevice: disk,
displayName: disk?.displayName,
forceFormatted,
provisioner: LONGHORN_DRIVER,
provisionerVersion: LONGHORN_VERSION_V1, // todo get default from system version
lvmVolumeGroup: null,
});
},
Expand All @@ -335,12 +347,9 @@ export default {
const updatedDisks = addDisks.filter((d) => {
const blockDevice = this.$store.getters[`${ inStore }/byId`](HCI.BLOCK_DEVICE, `${ LONGHORN_SYSTEM }/${ d.name }`);
const { provisioned, forceFormatted } = blockDevice.spec.fileSystem;
const { provisioner } = blockDevice.spec;
if (provisioned && forceFormatted === d.forceFormatted) {
return false;
} else {
return true;
}
return !(provisioned && forceFormatted === d.forceFormatted && isEqual(provisioner, d.provisioner));
});
if (updatedDisks.length === 0) {
Expand All @@ -355,6 +364,15 @@ export default {
blockDevice.spec.fileSystem.provisioned = true;
blockDevice.spec.fileSystem.forceFormatted = d.forceFormatted;
switch (d.provisioner) {
case LONGHORN_DRIVER:
blockDevice.spec.provisioner = { longhorn: { engineVersion: d.provisionerVersion } };
break;
case LVM_DRIVER:
blockDevice.spec.provisioner = { lvm: { vgName: d.lvmVolumeGroup } };
break;
}
return blockDevice.save();
}));
Expand Down
8 changes: 6 additions & 2 deletions pkg/harvester/edit/harvesterhci.io.storage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { STORAGE_CLASS, LONGHORN } from '@shell/config/types';
import { CSI_DRIVER } from '../../types';
import { allHash } from '@shell/utils/promise';
import { clone } from '@shell/utils/object';
import { LONGHORN_DRIVER } from '@shell/models/persistentvolume';
import { LONGHORN_DRIVER, LONGHORN_VERSION_V1, LONGHORN_VERSION_V2 } from '@shell/models/persistentvolume';
import { LVM_DRIVER } from '@shell/models/storage.k8s.io.storageclass';
const LONGHORN_V2_DATA_ENGINE = 'longhorn-system/v2-data-engine';
Expand Down Expand Up @@ -149,7 +149,11 @@ export default {
const inStore = this.$store.getters['currentProduct'].inStore;
const v2DataEngine = this.$store.getters[`${ inStore }/byId`](LONGHORN.SETTINGS, LONGHORN_V2_DATA_ENGINE) || {};
return v2DataEngine.value === 'true' ? 'v2' : 'v1';
return v2DataEngine.value === 'true' ? LONGHORN_VERSION_V2 : LONGHORN_VERSION_V1;
},
isLonghornV2() {
return this.value.provisioner === LONGHORN_DRIVER && this.longhornVersion === LONGHORN_VERSION_V2;
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { _CREATE, _VIEW } from '@shell/config/query-params';
import { LONGHORN } from '@shell/config/types';
import { clone } from '@shell/utils/object';
import { uniq } from '@shell/utils/array';
import { LONGHORN_VERSION_V1, LONGHORN_VERSION_V2 } from '@shell/models/persistentvolume';
const LONGHORN_V2_DATA_ENGINE = 'longhorn-system/v2-data-engine';
Expand Down Expand Up @@ -46,19 +47,22 @@ export default {
const inStore = this.$store.getters['currentProduct'].inStore;
const v2DataEngine = this.$store.getters[`${ inStore }/byId`](LONGHORN.SETTINGS, LONGHORN_V2_DATA_ENGINE) || {};
const longhornVersion = v2DataEngine.value === 'true' ? 'v2' : 'v1';
const longhornVersion = v2DataEngine.value === 'true' ? LONGHORN_VERSION_V2 : LONGHORN_VERSION_V1;
if (this.realMode === _CREATE) {
this.$set(this.value, 'parameters', {
numberOfReplicas: '3',
staleReplicaTimeout: '30',
diskSelector: null,
nodeSelector: null,
migratable: longhornVersion === 'v2' ? 'false' : 'true',
migratable: longhornVersion === LONGHORN_VERSION_V2 ? 'false' : 'true',
});
}
return { longhornVersion };
return {
LONGHORN_VERSION_V2,
longhornVersion
};
},
computed: {
Expand Down Expand Up @@ -236,7 +240,7 @@ export default {
:label="t('harvester.storage.parameters.migratable.label')"
:mode="mode"
:options="migratableOptions"
:disabled="longhornVersion === 'v2'"
:disabled="longhornVersion === LONGHORN_VERSION_V2"
/>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions pkg/harvester/l10n/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1056,10 +1056,10 @@ harvester:
storageClass:
label: Storage Class
longhorn:
v1:
label: Longhorn v1 (CSI)
v2:
label: Longhorn v2 (CSI)
LonghornV1:
label: LonghornV1 (CSI)
LonghornV2:
label: LonghornV2 (CSI)
lvm:
label: LVM
title: Storage Classes
Expand Down
2 changes: 2 additions & 0 deletions shell/models/persistentvolume.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export const VOLUME_PLUGINS = [
];

export const LONGHORN_DRIVER = 'driver.longhorn.io';
export const LONGHORN_VERSION_V1 = 'LonghornV1';
export const LONGHORN_VERSION_V2 = 'LonghornV2';

export const LONGHORN_PLUGIN = VOLUME_PLUGINS.find(plugin => plugin.value === 'longhorn');

Expand Down

0 comments on commit dedcf22

Please sign in to comment.