fix: when choose encrypt can only choose encrypted storage class when creating image

Signed-off-by: andy.lee <andy.lee@suse.com>
This commit is contained in:
andy.lee 2025-01-16 16:18:43 +08:00
parent 7b6efa624f
commit b0c7b1fefe
No known key found for this signature in database
GPG Key ID: 10911689462678C7
2 changed files with 35 additions and 4 deletions

View File

@ -24,6 +24,7 @@ const CLONE = 'clone';
const DOWNLOAD = 'download'; const DOWNLOAD = 'download';
const UPLOAD = 'upload'; const UPLOAD = 'upload';
const rawORqcow2 = 'raw_qcow2'; const rawORqcow2 = 'raw_qcow2';
const LONGHORN = 'longhorn';
export default { export default {
name: 'EditImage', name: 'EditImage',
@ -61,9 +62,7 @@ export default {
storageClasses: this.$store.dispatch(`${ inStore }/findAll`, { type: STORAGE_CLASS }), storageClasses: this.$store.dispatch(`${ inStore }/findAll`, { type: STORAGE_CLASS }),
}); });
const defaultStorage = this.$store.getters[`${ inStore }/all`](STORAGE_CLASS).find((s) => s.isDefault); this['storageClassName'] = this.storageClassName || this.defaultStorageClassName();
this['storageClassName'] = this.storageClassName || defaultStorage?.metadata?.name || 'longhorn';
this.images = this.$store.getters[`${ inStore }/all`](HCI.IMAGE); this.images = this.$store.getters[`${ inStore }/all`](HCI.IMAGE);
const { securityParameters } = this.value.spec; const { securityParameters } = this.value.spec;
@ -144,10 +143,23 @@ export default {
]; ];
}, },
storageClassOptions() { encryptedStorageClasses() {
const inStore = this.$store.getters['currentProduct'].inStore; const inStore = this.$store.getters['currentProduct'].inStore;
const storages = this.$store.getters[`${ inStore }/all`](STORAGE_CLASS); const storages = this.$store.getters[`${ inStore }/all`](STORAGE_CLASS);
return storages.filter((s) => s.isEncrypted);
},
nonEncryptedStorageClasses() {
const inStore = this.$store.getters['currentProduct'].inStore;
const storages = this.$store.getters[`${ inStore }/all`](STORAGE_CLASS);
return storages.filter((s) => !s.isEncrypted);
},
storageClassOptions() {
const storages = this.value.spec?.securityParameters?.cryptoOperation === ENCRYPT ? this.encryptedStorageClasses : this.nonEncryptedStorageClasses;
return storages return storages
.filter((s) => !s.parameters?.backingImage && s.provisioner !== LVM_DRIVER) // Lvm storage is not supported. .filter((s) => !s.parameters?.backingImage && s.provisioner !== LVM_DRIVER) // Lvm storage is not supported.
.map((s) => { .map((s) => {
@ -239,6 +251,13 @@ export default {
this.$refs.file.value = null; this.$refs.file.value = null;
} }
}, },
'value.spec.securityParameters.cryptoOperation'() {
if (this.value.spec?.securityParameters?.cryptoOperation === ENCRYPT) {
this.storageClassName = this.encryptedStorageClasses[0]?.name || LONGHORN;
} else { // URL / FILE / DECRYPT should use default storage class
this.storageClassName = this.defaultStorageClassName();
}
}
}, },
methods: { methods: {
@ -385,6 +404,14 @@ export default {
return str.toLowerCase().includes(os.value.toLowerCase()) ? os.value : false; return str.toLowerCase().includes(os.value.toLowerCase()) ? os.value : false;
} }
}); });
},
defaultStorageClassName() {
const inStore = this.$store.getters['currentProduct'].inStore;
const defaultStorage = this.$store.getters[`${ inStore }/all`](STORAGE_CLASS).find((s) => s.isDefault);
// if default sc is encrypted, use longhorn as default
return defaultStorage.isEncrypted ? LONGHORN : defaultStorage?.metadata?.name;
} }
}, },
}; };

View File

@ -58,6 +58,10 @@ export default class HciStorageClass extends StorageClass {
return key ? this.$rootGetters['i18n/t'](key) : this.provisioner; return key ? this.$rootGetters['i18n/t'](key) : this.provisioner;
} }
get isEncrypted() {
return this.parameters?.encrypted === 'true';
}
get isLonghornV2() { get isLonghornV2() {
return this.provisioner === LONGHORN_DRIVER && this.longhornVersion === DATA_ENGINE_V2; return this.provisioner === LONGHORN_DRIVER && this.longhornVersion === DATA_ENGINE_V2;
} }