From 6ce99fad1f5b8fbc1d60b6ec38c8ed78e0882933 Mon Sep 17 00:00:00 2001 From: "andy.lee" Date: Mon, 16 Sep 2024 13:54:56 +0800 Subject: [PATCH] add lock icon in VM list page --- .../VirtualMachineBasics.vue | 5 +-- pkg/harvester/l10n/en-us.yaml | 4 +++ .../list/kubevirt.io.virtualmachine.vue | 31 +++++++++++++++---- .../models/harvester/persistentvolumeclaim.js | 6 +--- .../models/kubevirt.io.virtualmachine.js | 23 ++++++++++++++ 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/pkg/harvester/detail/kubevirt.io.virtualmachine/VirtualMachineTabs/VirtualMachineBasics.vue b/pkg/harvester/detail/kubevirt.io.virtualmachine/VirtualMachineTabs/VirtualMachineBasics.vue index 98703e1b..9f9ac09d 100644 --- a/pkg/harvester/detail/kubevirt.io.virtualmachine/VirtualMachineTabs/VirtualMachineBasics.vue +++ b/pkg/harvester/detail/kubevirt.io.virtualmachine/VirtualMachineTabs/VirtualMachineBasics.vue @@ -63,10 +63,7 @@ export default { imageName() { const imageList = this.$store.getters['harvester/all'](HCI.IMAGE) || []; - - const image = imageList.find( (I) => { - return this.value.rootImageId === I.id; - }); + const image = imageList.find( I => this.value.rootImageId === I.id); return image?.spec?.displayName || 'N/A'; }, diff --git a/pkg/harvester/l10n/en-us.yaml b/pkg/harvester/l10n/en-us.yaml index e1e7c633..1270adec 100644 --- a/pkg/harvester/l10n/en-us.yaml +++ b/pkg/harvester/l10n/en-us.yaml @@ -640,6 +640,10 @@ harvester: userTips: The user to be added must already exist; otherwise, the credentials will not take effect. duplicatedUser: User already exists. invalidUser: Invalid Username. + lockIconTooltip: + image: Image encrypted + volume: Volume encrypted + both: Image encrypted and volume encrypted input: name: Name memory: Memory diff --git a/pkg/harvester/list/kubevirt.io.virtualmachine.vue b/pkg/harvester/list/kubevirt.io.virtualmachine.vue index 73d44691..f9b499f2 100644 --- a/pkg/harvester/list/kubevirt.io.virtualmachine.vue +++ b/pkg/harvester/list/kubevirt.io.virtualmachine.vue @@ -1,9 +1,7 @@ @@ -194,11 +208,16 @@ export default { diff --git a/pkg/harvester/models/harvester/persistentvolumeclaim.js b/pkg/harvester/models/harvester/persistentvolumeclaim.js index 816a7b29..645b1586 100644 --- a/pkg/harvester/models/harvester/persistentvolumeclaim.js +++ b/pkg/harvester/models/harvester/persistentvolumeclaim.js @@ -214,11 +214,7 @@ export default class HciPv extends HarvesterResource { } get isEncrypted() { - const inStore = this.$rootGetters['currentProduct'].inStore; - - const longhornVolume = this.$rootGetters[`${ inStore }/all`](LONGHORN.VOLUMES).find(v => v.metadata?.name === this.spec?.volumeName); - - return longhornVolume?.spec.encrypted || false; + return this.relatedPV?.spec.csi.volumeAttributes.encrypted || false; } get longhornVolume() { diff --git a/pkg/harvester/models/kubevirt.io.virtualmachine.js b/pkg/harvester/models/kubevirt.io.virtualmachine.js index f7a02958..82652bd0 100644 --- a/pkg/harvester/models/kubevirt.io.virtualmachine.js +++ b/pkg/harvester/models/kubevirt.io.virtualmachine.js @@ -574,6 +574,29 @@ export default class VirtVm extends HarvesterResource { return vmis.find(VMI => VMI.id === this.id); } + get isVMImageEncrypted() { + const inStore = this.productInStore; + const imageList = this.$rootGetters[`${ inStore }/all`](HCI.IMAGE); + const rootImage = imageList.find(image => this.rootImageId === image.id); + + return rootImage?.isEncrypted || false; + } + + get isVolumeEncrypted() { + const inStore = this.productInStore; + const pvcs = this.$rootGetters[`${ inStore }/all`](PVC); + + // filter out the root image PVC + const nonRootImagePVCs = pvcs.filter(pvc => !pvc.metadata.annotations[HCI_ANNOTATIONS.IMAGE_ID]); + + const volumeClaimNames = this.spec.template.spec.volumes?.map(v => v.persistentVolumeClaim?.claimName).map(v => v) || []; + + const pvcVolumes = nonRootImagePVCs.filter(pvc => volumeClaimNames.includes(pvc.metadata.name)); + + // if any non-rootImage PCV volume is encrypted, return true, otherwise return false + return pvcVolumes.some(pvcVol => pvcVol.isEncrypted) ; + } + get isError() { const conditions = get(this.vmi, 'status.conditions'); const vmiFailureCond = findBy(conditions, 'type', 'Failure');