Skip to content

Add disks labels to provisioned disks (POSTPONE to v1.6.0) #951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/harvester/edit/harvesterhci.io.host/HarvesterDisk.vue
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export default {
color="info"
:label="formattedBannerLabel"
/>
<div v-if="!value.isNew">
<div>
<div class="row">
<div class="col span-12">
<Tags
Expand All @@ -358,7 +358,7 @@ export default {
/>
</div>
</div>
<div class="row mt-10">
<div v-if="!value.isNew" class="row mt-10">
<div class="col span-12">
<div class="pull-left">
<RadioGroup
Expand Down
34 changes: 26 additions & 8 deletions pkg/harvester/edit/harvesterhci.io.host/index.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script>
import { isEqual } from 'lodash';
import { mapGetters } from 'vuex';
import Tabbed from '@shell/components/Tabbed';
import Tab from '@shell/components/Tabbed/Tab';
Expand Down Expand Up @@ -31,7 +32,6 @@ import HarvesterSeeder from './HarvesterSeeder';
import Tags from '../../components/DiskTags';
import { LONGHORN_DRIVER, LONGHORN_VERSION_V1, LONGHORN_VERSION_V2 } from '@shell/models/persistentvolume';
import { LVM_DRIVER } from '../../models/harvester/storage.k8s.io.storageclass';
import isEqual from 'lodash/isEqual';

export const LONGHORN_SYSTEM = 'longhorn-system';

Expand Down Expand Up @@ -101,6 +101,7 @@ export default {
provisioner: d?.spec?.provisioner?.lvm ? LVM_DRIVER : LONGHORN_DRIVER,
provisionerVersion: d?.spec?.provisioner?.longhorn?.engineVersion || LONGHORN_VERSION_V1,
lvmVolumeGroup: d?.spec?.provisioner?.lvm?.vgName,
tags: d?.spec?.tags || [],
};
});

Expand Down Expand Up @@ -342,16 +343,22 @@ export default {
provisioner: LONGHORN_DRIVER,
provisionerVersion: LONGHORN_VERSION_V1,
lvmVolumeGroup: null,
tags: []
});
},

async saveDisk() {
const inStore = this.$store.getters['currentProduct'].inStore;
const addDisks = this.newDisks.filter(d => d.isNew);
const removeDisks = this.disks.filter(d => !findBy(this.newDisks, 'name', d.name) && d.blockDevice);
let tagDisks = [];

if (addDisks.length === 0 && removeDisks.length === 0) {
return Promise.resolve();
tagDisks = this.newDisks.filter(d => d.blockDevice && !isEqual(d.blockDevice.spec.tags, d.tags));

if (tagDisks.length === 0) {
return Promise.resolve();
}
} else if (addDisks.length !== 0 && removeDisks.length === 0) {
const updatedDisks = addDisks.filter((d) => {
const blockDevice = this.$store.getters[`${ inStore }/byId`](HCI.BLOCK_DEVICE, `${ LONGHORN_SYSTEM }/${ d.name }`);
Expand All @@ -372,6 +379,7 @@ export default {

blockDevice.spec.provision = true;
blockDevice.spec.fileSystem.forceFormatted = d.forceFormatted;
blockDevice.spec.tags = d.tags;

switch (d.provisioner) {
case LONGHORN_DRIVER:
Expand All @@ -393,6 +401,14 @@ export default {
return blockDevice.save();
}));

await Promise.all(tagDisks.map((d) => {
const blockDevice = this.$store.getters[`${ inStore }/byId`](HCI.BLOCK_DEVICE, `${ LONGHORN_SYSTEM }/${ d.name }`);

blockDevice.spec.tags = d.tags;

return blockDevice.save();
}));

this.$store.dispatch('growl/success', {
title: this.t('generic.notification.title.succeed'),
message: this.t('harvester.host.disk.notification.success', { name: this.value.metadata?.name || '' }),
Expand Down Expand Up @@ -503,17 +519,19 @@ export default {
async saveLonghornNode() {
const inStore = this.$store.getters['currentProduct'].inStore;

const disks = this.longhornNode?.spec?.disks || {};
const storageTags = clone(this.longhornNode?.spec?.tags);

// update each disk tags and scheduling
this.newDisks.map((disk) => {
(disks[disk.name] || {}).tags = disk.tags;
(disks[disk.name] || {}).allowScheduling = disk.allowScheduling;
});
let count = 0;

const retrySave = async() => {
try {
this.longhornNode.spec.tags = storageTags;

this.newDisks.forEach((disk) => {
(this.longhornNode?.spec?.disks?.[disk.name] || {}).tags = disk.tags;
(this.longhornNode?.spec?.disks?.[disk.name] || {}).allowScheduling = disk.allowScheduling;
});

await this.longhornNode.save();
} catch (err) {
if ((err.status === 409 || err.status === 403) && count < 3) {
Expand Down