fix: use longhorn-static for upgrade vmimage (#690) (#692)

(cherry picked from commit 0647600e88b59ccdf6a8d8f78d88b972cd604185)

Signed-off-by: Cooper Tseng <cooper.tseng@suse.com>
This commit is contained in:
mergify[bot] 2026-01-22 09:51:01 +08:00 committed by GitHub
parent 9e588e90c2
commit 5488979448
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,7 +12,6 @@ import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../../../../config/harvester'
import ImagePercentageBar from '@shell/components/formatter/ImagePercentageBar'; import ImagePercentageBar from '@shell/components/formatter/ImagePercentageBar';
import { Banner } from '@components/Banner'; import { Banner } from '@components/Banner';
import isEmpty from 'lodash/isEmpty'; import isEmpty from 'lodash/isEmpty';
import { STORAGE_CLASS } from '@shell/config/types';
const IMAGE_METHOD = { const IMAGE_METHOD = {
NEW: 'new', NEW: 'new',
@ -33,7 +32,6 @@ export default {
async fetch() { async fetch() {
await this.$store.dispatch('harvester/findAll', { type: HCI.IMAGE }); await this.$store.dispatch('harvester/findAll', { type: HCI.IMAGE });
await this.$store.dispatch('harvester/findAll', { type: STORAGE_CLASS });
const value = await this.$store.dispatch('harvester/create', { const value = await this.$store.dispatch('harvester/create', {
type: HCI.UPGRADE, type: HCI.UPGRADE,
@ -65,7 +63,6 @@ export default {
sourceType: UPLOAD, sourceType: UPLOAD,
uploadController: null, uploadController: null,
uploadResult: null, uploadResult: null,
storageClassValue: null,
imageValue: null, imageValue: null,
enableLogging: true, enableLogging: true,
IMAGE_METHOD, IMAGE_METHOD,
@ -183,38 +180,6 @@ export default {
}); });
}, },
async createImageStorageClass(imageName = '') {
// delete related SC if existed
await this.deleteImageStorageClass(imageName);
const storageClassPayload = {
apiVersion: 'storage.k8s.io/v1',
type: STORAGE_CLASS,
metadata: { name: imageName },
volumeBindingMode: 'Immediate',
reclaimPolicy: 'Delete',
allowVolumeExpansion: true, // must be boolean type
provisioner: 'driver.longhorn.io',
};
this.storageClassValue = await this.$store.dispatch('harvester/create', storageClassPayload);
if (this.storageClassValue && this.storageClassValue.save) {
await this.storageClassValue.save();
}
},
async deleteImageStorageClass(imageName = '') {
const inStore = this.$store.getters['currentProduct'].inStore;
const storageClasses = this.$store.getters[`${ inStore }/all`](STORAGE_CLASS);
const targetSC = storageClasses.find((sc) => sc.id === imageName);
if (targetSC && targetSC.remove) {
await targetSC.remove();
}
},
async initImageValue() { async initImageValue() {
this.imageValue = await this.$store.dispatch('harvester/create', { this.imageValue = await this.$store.dispatch('harvester/create', {
type: HCI.IMAGE, type: HCI.IMAGE,
@ -263,10 +228,8 @@ export default {
return; return;
} }
// create related image storage class first
await this.createImageStorageClass(imageDisplayName);
this.imageValue.spec.sourceType = DOWNLOAD; this.imageValue.spec.sourceType = DOWNLOAD;
this.imageValue.spec.targetStorageClassName = imageDisplayName; this.imageValue.spec.targetStorageClassName = 'longhorn-static';
res = await this.imageValue.save(); res = await this.imageValue.save();
@ -295,8 +258,6 @@ export default {
} catch (e) { } catch (e) {
this.errors = [e?.message] || exceptionToErrorsArray(e); this.errors = [e?.message] || exceptionToErrorsArray(e);
buttonCb(false); buttonCb(false);
// if anything failed, delete the created image storage class
await this.deleteImageStorageClass(imageDisplayName);
} }
}, },
@ -325,9 +286,7 @@ export default {
this.imageValue.spec.url = ''; this.imageValue.spec.url = '';
try { try {
// before uploading image, we need to create related image storage class first this.imageValue.spec.targetStorageClassName = 'longhorn-static';
await this.createImageStorageClass(fileName);
this.imageValue.spec.targetStorageClassName = fileName;
const res = await this.imageValue.save(); const res = await this.imageValue.save();
@ -345,8 +304,6 @@ export default {
} else { } else {
this.errors = exceptionToErrorsArray(e); this.errors = exceptionToErrorsArray(e);
} }
// if upload failed, delete the created image storage class
await this.deleteImageStorageClass(fileName);
this.file = {}; this.file = {};
this.uploadImageId = ''; this.uploadImageId = '';
} }
@ -371,9 +328,6 @@ export default {
component: 'ConfirmRelatedToRemoveDialog', component: 'ConfirmRelatedToRemoveDialog',
needConfirmation: false, needConfirmation: false,
warningMessage: this.$store.getters['i18n/t']('harvester.modal.osImage.message', { name: imageDisplayName }), warningMessage: this.$store.getters['i18n/t']('harvester.modal.osImage.message', { name: imageDisplayName }),
extraActionAfterRemove: async() => {
await this.deleteImageStorageClass(imageDisplayName);
}
}); });
this.deleteImageId = ''; this.deleteImageId = '';
} }