Skip to content

Commit

Permalink
add lock icon in VM list page
Browse files Browse the repository at this point in the history
  • Loading branch information
a110605 committed Sep 16, 2024
1 parent f1a22a2 commit 117cb41
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
},
Expand Down
4 changes: 4 additions & 0 deletions pkg/harvester/l10n/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,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
Expand Down
32 changes: 25 additions & 7 deletions pkg/harvester/list/kubevirt.io.virtualmachine.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<script>
import ConsoleBar from '../components/VMConsoleBar';
import ResourceTable from '@shell/components/ResourceTable';
import LinkDetail from '@shell/components/formatter/LinkDetail';
import HarvesterVmState from '../formatters/HarvesterVmState';
import { PVC, PV, NODE, POD } from '@shell/config/types';
import { STATE, AGE, NAME, NAMESPACE } from '@shell/config/table-headers';
import { NODE, POD } from '@shell/config/types';
import { HCI } from '../types';
import { allHash } from '@shell/utils/promise';
import Loading from '@shell/components/Loading';
import { clone } from '@shell/utils/object';
Expand Down Expand Up @@ -60,7 +57,6 @@ export default {
components: {
Loading,
HarvesterVmState,
LinkDetail,
ConsoleBar,
ResourceTable
},
Expand All @@ -77,6 +73,9 @@ export default {
const _hash = {
vms: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.VM }),
pod: this.$store.dispatch(`${ inStore }/findAll`, { type: POD }),
pvcs: this.$store.dispatch(`${ inStore }/findAll`, { type: PVC }),
pvs: this.$store.dispatch(`${ inStore }/findAll`, { type: PV }),
images: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.IMAGE }),
restore: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.RESTORE }),
backups: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.BACKUP }),
};
Expand Down Expand Up @@ -169,6 +168,20 @@ export default {
await this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.VMIM });
this.$set(this, 'allVMIs', vmis);
},
methods: {
lockIconTooltipMessage(row) {
if (row.isVMImageEncrypted && row.isVolumeEncrypted) {
return this.t('harvester.virtualMachine.lockIconTooltip.both');
} else if (row.isVMImageEncrypted) {
return this.t('harvester.virtualMachine.lockIconTooltip.image');
} else if (row.isVolumeEncrypted) {
return this.t('harvester.virtualMachine.lockIconTooltip.volume');
}
return '';
}
}
};
</script>
Expand All @@ -194,11 +207,16 @@ export default {

<template slot="cell:name" slot-scope="scope">
<div class="name-console">
<LinkDetail v-if="scope.row.type !== HCI.VMI" v-model="scope.row.metadata.name" :row="scope.row" />
<n-link
v-if="scope.row.type !== HCI.VMI"
:to="scope.row.detailLocation"
>
{{ scope.row.metadata.name }}
<i v-if="scope.row.isVMImageEncrypted || scope.row.isVolumeEncrypted" v-tooltip="lockIconTooltipMessage(scope.row)" class="icon icon-lock" />
</n-link>
<span v-else>
{{ scope.row.metadata.name }}
</span>

<ConsoleBar :resource="scope.row" class="console mr-10 ml-10" />
</div>
</template>
Expand Down
6 changes: 1 addition & 5 deletions pkg/harvester/models/harvester/persistentvolumeclaim.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,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() {
Expand Down
23 changes: 23 additions & 0 deletions pkg/harvester/models/kubevirt.io.virtualmachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,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');
Expand Down

0 comments on commit 117cb41

Please sign in to comment.