Skip to content

Commit

Permalink
Add lvm node selector
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
  • Loading branch information
torchiaf committed Sep 17, 2024
1 parent 8f79581 commit 11818f9
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default {
}
},
provisioner() {
provisioner() {
let labelKey = `harvester.storage.storageClass.longhorn.${ LONGHORN_VERSION_V1 }.label`;
if (this.value?.blockDevice?.spec?.provisioner.longhorn) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/harvester/edit/harvesterhci.io.host/HarvesterDisk.vue
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export default {
:label="t('harvester.host.disk.fileSystem.formatting')"
/>
<Banner
v-else-if="isFormatted && !isCorrupted"
v-else-if="isFormatted && isLonghornV1 && !isCorrupted"
color="info"
:label="formattedBannerLabel"
/>
Expand Down Expand Up @@ -333,6 +333,7 @@ export default {
:localized-label="true"
:searchable="true"
:options="provisioners"
:disabled="isProvisioned"
@keydown.native.enter.prevent="()=>{}"
/>
</div>
Expand Down Expand Up @@ -367,6 +368,7 @@ export default {
:searchable="true"
:options="lvmVolumeGroups"
:required="true"
:disabled="isProvisioned"
@keydown.native.enter.prevent="()=>{}"
/>
</div>
Expand Down
8 changes: 8 additions & 0 deletions pkg/harvester/edit/harvesterhci.io.storage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ export default {
isLonghornV2() {
return this.value.provisioner === LONGHORN_DRIVER && this.longhornVersion === LONGHORN_VERSION_V2;
},
isLvm() {
return this.value.provisioner === LVM_DRIVER;
},
},
watch: {
Expand All @@ -165,6 +169,10 @@ export default {
parameters.migratable = false;
}
if (!this.isLvm) {
this.$set(this.value, 'allowedTopologies', []);
}
this.$set(this.value, 'parameters', parameters);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@
import KeyValue from '@shell/components/form/KeyValue';
import LabeledSelect from '@shell/components/form/LabeledSelect';
import { LabeledInput } from '@components/Form/LabeledInput';
import RadioGroup from '@components/Form/Radio/RadioGroup';
import { allHash } from '@shell/utils/promise';
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';
import merge from 'lodash/merge';
import { HCI } from '../../../types';
import { NODE } from '@shell/config/types';
const TOPOLOGY_LABEL = 'topology.lvm.csi/node';
const DEFAULT_PARAMETERS = [
'type',
'vgName'
];
const DEFAUL_TOPOLOGIES = [{
matchLabelExpressions: [{
key: TOPOLOGY_LABEL,
values: []
}]
}];
export default {
components: {
KeyValue,
LabeledSelect,
LabeledInput,
RadioGroup,
},
props: {
Expand All @@ -45,28 +48,53 @@ export default {
const inStore = this.$store.getters['currentProduct'].inStore;
await allHash({
nodes: this.$store.dispatch(`${ inStore }/findAll`, { type: NODE }),
lvmVolumeGroups: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.LVM_VOLUME_GROUP }),
});
},
data() {
const node = this.value.allowedTopologies
?.find(t => t.matchLabelExpressions
?.find(labelExpr => labelExpr.key === TOPOLOGY_LABEL))?.matchLabelExpressions[0].values[0];
return {
volumeGroupTypes: ['striped', 'dm-thin'],
volumeGroupType: null,
volumeGroup: null,
nodeName: 'harvester-node-0'
node,
};
},
watch: {
node(value) {
delete (this.value.parameters.vgName);
const allowedTopologies = [...DEFAUL_TOPOLOGIES];
allowedTopologies[0].matchLabelExpressions[0].values = [value];
merge([], allowedTopologies, this.value.allowedTopologies || []);
this.value.allowedTopologies = allowedTopologies;
}
},
computed: {
nodes() {
const inStore = this.$store.getters['currentProduct'].inStore;
const nodes = this.$store.getters[`${ inStore }/all`](NODE) || [];
return nodes.map(n => n.name);
},
volumeGroups() {
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.nodeName)
.filter(group => group.spec.nodeName === this.node)
.map(g => g.spec.vgName);
},
parameters: {
get() {
const parameters = clone(this.value?.parameters) || {};
Expand All @@ -90,7 +118,24 @@ export default {
<div class="row mt-10">
<div class="col span-6">
<LabeledSelect
v-model="volumeGroup"
v-model="node"
:label="t('harvester.storage.parameters.node.label')"
:options="nodes"
:mode="mode"
:required="true"
>
<template #no-options="{ searching }">
<span v-if="!searching" class="text-muted">
{{ t('harvester.storage.parameters.diskSelector.no-options', null, true) }}
</span>
</template>
</LabeledSelect>
</div>
</div>
<div class="row mt-10">
<div class="col span-6">
<LabeledSelect
v-model="value.parameters.vgName"
:label="t('harvester.storage.parameters.lvmVolumeGroup.label')"
:options="volumeGroups"
:mode="mode"
Expand All @@ -105,7 +150,7 @@ export default {
</div>
<div class="col span-6">
<LabeledSelect
v-model="volumeGroupType"
v-model="value.parameters.type"
:label="t('harvester.storage.parameters.lvmVolumeGroupType.label')"
:options="volumeGroupTypes"
:mode="mode"
Expand Down Expand Up @@ -134,4 +179,3 @@ export default {
padding: 7px 10px;
}
</style>
2 changes: 2 additions & 0 deletions pkg/harvester/l10n/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,8 @@ harvester:
label: Volume Group Type
lvmVolumeGroup:
label: Volume Group Name
node:
label: Node
allowedTopologies:
title: Allowed Topologies
tooltip: Allowed Topologies helps scheduling virtual machines on hosts which match all of below expressions.
Expand Down

0 comments on commit 11818f9

Please sign in to comment.