mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-02-04 06:51:44 +00:00
fix: use longhorn-static for upgrade vmimage (#690)
Signed-off-by: Cooper Tseng <cooper.tseng@suse.com>
This commit is contained in:
parent
99dbba7958
commit
0647600e88
@ -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 = '';
|
||||||
}
|
}
|
||||||
@ -367,13 +324,10 @@ export default {
|
|||||||
|
|
||||||
if (image && imageDisplayName) {
|
if (image && imageDisplayName) {
|
||||||
this.$store.dispatch('harvester/promptModal', {
|
this.$store.dispatch('harvester/promptModal', {
|
||||||
resources: [image],
|
resources: [image],
|
||||||
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 = '';
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user