Skip to content
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

fix: encrypt option can only choose encrypted storage class when creating VM image #93

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 31 additions & 4 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 @@ -61,9 +62,7 @@ export default {
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 +143,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 +251,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 || LONGHORN;
} else { // URL / FILE / DECRYPT should use default storage class
this.storageClassName = this.defaultStorageClassName();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use this.value.metadata.annotations[HCI_ANNOTATIONS.STORAGE_CLASS] to retrieve the storageClassName on line 177.
Is this value always be the same of this.$store.getters[${ inStore }/all](STORAGE_CLASS).find((s) => s.isDefault)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in 6e9350e

}
}
},

methods: {
Expand Down Expand Up @@ -385,6 +404,14 @@ 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fallback to longhorn is there is no defaultStorage?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. If there is no default SC, we can fallback to longhorn.


// if default sc is encrypted, use longhorn as default
return defaultStorage.isEncrypted ? LONGHORN : defaultStorage?.metadata?.name;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any chance that longhorn could be deleted, or is it not deletable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Longhorn sc can be deleted from UI. But backend won't actually delete it.
cc @Vicente-Cheng
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was actually deleted but soon was recreated by someone...

}
},
};
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
Loading