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 18, 2024
1 parent 8f79581 commit 5e5c898
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 21 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
28 changes: 24 additions & 4 deletions pkg/harvester/edit/harvesterhci.io.storage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { LONGHORN_DRIVER, LONGHORN_VERSION_V1, LONGHORN_VERSION_V2 } from '@shel
import { LVM_DRIVER } from '@shell/models/storage.k8s.io.storageclass';
const LONGHORN_V2_DATA_ENGINE = 'longhorn-system/v2-data-engine';
export const LVM_TOPOLOGY_LABEL = 'topology.lvm.csi/node';

Check warning on line 25 in pkg/harvester/edit/harvesterhci.io.storage/index.vue

View workflow job for this annotation

GitHub Actions / lint

Expected blank line before this statement
export default {
name: 'HarvesterStorage',
Expand Down Expand Up @@ -72,7 +73,7 @@ export default {
}
];
const allowedTopologies = clone(this.value.allowedTopologies?.[0]?.matchLabelExpressions || []);
const allowedTopologies = clone(this.value.allowedTopologies?.[0]?.matchLabelExpressions || []).filter((t) => t.key !== LVM_TOPOLOGY_LABEL);

Check warning on line 76 in pkg/harvester/edit/harvesterhci.io.storage/index.vue

View workflow job for this annotation

GitHub Actions / lint

Unexpected parentheses around single function argument having a body with no curly braces
this.$set(this.value, 'parameters', this.value.parameters || {});
this.$set(this.value, 'provisioner', this.value.provisioner || LONGHORN_DRIVER);
Expand Down Expand Up @@ -155,6 +156,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 +170,16 @@ export default {
parameters.migratable = false;
}
if (!this.isLvm) {
const matchLabelExpressions = (this.value.allowedTopologies?.[0]?.matchLabelExpressions || []).filter((t) => t.key !== LVM_TOPOLOGY_LABEL);

Check warning on line 174 in pkg/harvester/edit/harvesterhci.io.storage/index.vue

View workflow job for this annotation

GitHub Actions / lint

Unexpected parentheses around single function argument having a body with no curly braces

Check warning on line 175 in pkg/harvester/edit/harvesterhci.io.storage/index.vue

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
if (matchLabelExpressions.length > 0) {
this.$set(this.value, 'allowedTopologies', [{ matchLabelExpressions }]);
} else {
delete this.value.allowedTopologies;
}
}
this.$set(this.value, 'parameters', parameters);
}
},
Expand Down Expand Up @@ -198,18 +213,23 @@ export default {
},
formatAllowedTopoloties() {
const neu = this.allowedTopologies;
const neu = this.allowedTopologies.filter((t) => t.key !== LVM_TOPOLOGY_LABEL);

Check warning on line 216 in pkg/harvester/edit/harvesterhci.io.storage/index.vue

View workflow job for this annotation

GitHub Actions / lint

Unexpected parentheses around single function argument having a body with no curly braces
const lvmMatchExpression = (this.value.allowedTopologies?.[0]?.matchLabelExpressions || []).filter((t) => t.key === LVM_TOPOLOGY_LABEL);

Check warning on line 217 in pkg/harvester/edit/harvesterhci.io.storage/index.vue

View workflow job for this annotation

GitHub Actions / lint

Unexpected parentheses around single function argument having a body with no curly braces
if (!neu || neu.length === 0) {
delete this.value.allowedTopologies;
if (lvmMatchExpression.length > 0) {
this.value.allowedTopologies = [{ matchLabelExpressions: lvmMatchExpression }];
} else {
delete this.value.allowedTopologies;
}
return;
}
const matchLabelExpressions = neu.filter(R => !!R.key.trim() && (R.values.length > 0 && !R.values.find(V => !V.trim())));
if (matchLabelExpressions.length > 0) {
this.value.allowedTopologies = [{ matchLabelExpressions }];
this.value.allowedTopologies = [{ matchLabelExpressions: [ ...matchLabelExpressions, ...lvmMatchExpression ] }];

Check warning on line 232 in pkg/harvester/edit/harvesterhci.io.storage/index.vue

View workflow job for this annotation

GitHub Actions / lint

There should be no space after '['

Check warning on line 232 in pkg/harvester/edit/harvesterhci.io.storage/index.vue

View workflow job for this annotation

GitHub Actions / lint

There should be no space before ']'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@
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 { HCI } from '../../../types';
import { NODE } from '@shell/config/types';
import { LVM_TOPOLOGY_LABEL } from '../index.vue';
const DEFAULT_PARAMETERS = [
'type',
'vgName'
];
const DEFAUL_TOPOLOGIES = [{
matchLabelExpressions: [{
key: LVM_TOPOLOGY_LABEL,
values: []
}]
}];
export default {
components: {
KeyValue,
LabeledSelect,
LabeledInput,
RadioGroup,
},
props: {
Expand All @@ -45,28 +46,49 @@ 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?.[0]?.matchLabelExpressions || []).find((t) => t.key === LVM_TOPOLOGY_LABEL)?.values[0];

Check warning on line 55 in pkg/harvester/edit/harvesterhci.io.storage/provisioners/lvm.driver.harvesterhci.io.vue

View workflow job for this annotation

GitHub Actions / lint

Unexpected parentheses around single function argument having a body with no curly braces
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];
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 +112,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 +144,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 +173,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 5e5c898

Please sign in to comment.