Skip to content

Commit

Permalink
Merge pull request #99 from harvester/mergify/bp/release-harvester-v1…
Browse files Browse the repository at this point in the history
….5/pr-93

fix: encrypt option can only choose encrypted storage class when creating VM image (backport #93)
  • Loading branch information
a110605 authored Jan 20, 2025
2 parents def4b64 + fb8a81f commit a640598
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
40 changes: 35 additions & 5 deletions pkg/harvester/edit/harvesterhci.io.virtualmachineimage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const CLONE = 'clone';
const DOWNLOAD = 'download';
const UPLOAD = 'upload';
const rawORqcow2 = 'raw_qcow2';
const LONGHORN = 'longhorn';
export default {
name: 'EditImage',
Expand Down Expand Up @@ -60,10 +61,7 @@ export default {
images: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.IMAGE }),
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 || defaultStorage?.metadata?.name || 'longhorn';
this['storageClassName'] = this.storageClassName || this.defaultStorageClassName();
this.images = this.$store.getters[`${ inStore }/all`](HCI.IMAGE);
const { securityParameters } = this.value.spec;
Expand Down Expand Up @@ -144,10 +142,23 @@ export default {
];
},
storageClassOptions() {
encryptedStorageClasses() {
const inStore = this.$store.getters['currentProduct'].inStore;
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
.filter((s) => !s.parameters?.backingImage && s.provisioner !== LVM_DRIVER) // Lvm storage is not supported.
.map((s) => {
Expand Down Expand Up @@ -239,6 +250,13 @@ export default {
this.$refs.file.value = null;
}
},
'value.spec.securityParameters.cryptoOperation'() {
if (this.value.spec?.securityParameters?.cryptoOperation === ENCRYPT) {
this.storageClassName = this.encryptedStorageClasses[0]?.name || '';
} else { // URL / FILE / DECRYPT should use default storage class
this.storageClassName = this.defaultStorageClassName();
}
}
},
methods: {
Expand Down Expand Up @@ -385,6 +403,18 @@ export default {
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 (!defaultStorage) {
return LONGHORN;
}
// if default sc is encrypted, use longhorn as default
return defaultStorage.isEncrypted ? LONGHORN : defaultStorage?.metadata?.name;
}
},
};
Expand Down
4 changes: 4 additions & 0 deletions pkg/harvester/models/harvester/storage.k8s.io.storageclass.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export default class HciStorageClass extends StorageClass {
return key ? this.$rootGetters['i18n/t'](key) : this.provisioner;
}

get isEncrypted() {
return this.parameters?.encrypted === 'true';
}

get isLonghornV2() {
return this.provisioner === LONGHORN_DRIVER && this.longhornVersion === DATA_ENGINE_V2;
}
Expand Down

0 comments on commit a640598

Please sign in to comment.