From 4d4342b8ca7a5d10208ea371062686f86b3a8f5a Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Tue, 8 Oct 2024 11:54:13 +0200 Subject: [PATCH 1/4] Remove "Take Snapshot" action for Longhorn V2 Storage Classes Signed-off-by: Francesco Torchia (cherry picked from commit 67f76386e8272770f10e15452ff5fcf3166dfbc5) --- .../models/harvester/persistentvolumeclaim.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/harvester/models/harvester/persistentvolumeclaim.js b/pkg/harvester/models/harvester/persistentvolumeclaim.js index 176085254e6..fdc9c01b901 100644 --- a/pkg/harvester/models/harvester/persistentvolumeclaim.js +++ b/pkg/harvester/models/harvester/persistentvolumeclaim.js @@ -49,6 +49,12 @@ export default class HciPv extends HarvesterResource { icon: 'icon icon-copy', label: this.t('harvester.action.exportImage') }, + { + action: 'snapshot', + enabled: this.hasAction('snapshot'), + icon: 'icon icon-backup', + label: this.t('harvester.action.snapshot'), + }, ...out ]; } @@ -60,12 +66,6 @@ export default class HciPv extends HarvesterResource { icon: 'icon icon-backup', label: this.t('harvester.action.cancelExpand') }, - { - action: 'snapshot', - enabled: this.hasAction('snapshot'), - icon: 'icon icon-backup', - label: this.t('harvester.action.snapshot'), - }, ...out ]; } From bada88dff6f184a36a79704923d68d3f4c97527e Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Tue, 8 Oct 2024 12:54:15 +0200 Subject: [PATCH 2/4] Remove "Take Snapshot" action for Longhorn V2 Vms Signed-off-by: Francesco Torchia (cherry picked from commit 5d359aa11cf18e8664e0283cd7020b5d59f485e6) --- .../list/kubevirt.io.virtualmachine.vue | 3 ++- .../harvester/storage.k8s.io.storageclass.js | 6 +++++- .../models/kubevirt.io.virtualmachine.js | 19 ++++++++++++------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/pkg/harvester/list/kubevirt.io.virtualmachine.vue b/pkg/harvester/list/kubevirt.io.virtualmachine.vue index 8e63db59dd1..0ab2e5bc86b 100644 --- a/pkg/harvester/list/kubevirt.io.virtualmachine.vue +++ b/pkg/harvester/list/kubevirt.io.virtualmachine.vue @@ -2,7 +2,7 @@ import ConsoleBar from '../components/VMConsoleBar'; import ResourceTable from '@shell/components/ResourceTable'; import HarvesterVmState from '../formatters/HarvesterVmState'; -import { PVC, PV, NODE, POD } from '@shell/config/types'; +import { PVC, PV, NODE, POD, STORAGE_CLASS } from '@shell/config/types'; import { STATE, AGE, NAME, NAMESPACE } from '@shell/config/table-headers'; import { HCI } from '../types'; import { allHash } from '@shell/utils/promise'; @@ -78,6 +78,7 @@ export default { 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 }), + storage: this.$store.dispatch(`${ inStore }/findAll`, { type: STORAGE_CLASS }), }; if (this.$store.getters[`${ inStore }/schemaFor`](HCI.RESOURCE_QUOTA)) { diff --git a/pkg/harvester/models/harvester/storage.k8s.io.storageclass.js b/pkg/harvester/models/harvester/storage.k8s.io.storageclass.js index 983e2af9413..78f8b0b11f5 100644 --- a/pkg/harvester/models/harvester/storage.k8s.io.storageclass.js +++ b/pkg/harvester/models/harvester/storage.k8s.io.storageclass.js @@ -3,7 +3,7 @@ import { HCI } from '../../types'; import StorageClass from '@shell/models/storage.k8s.io.storageclass'; import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../../config/harvester'; import { LONGHORN_DRIVER } from '@shell/models/persistentvolume'; -import { DATA_ENGINE_V1 } from '../../edit/harvesterhci.io.storage/index.vue'; +import { DATA_ENGINE_V1, DATA_ENGINE_V2 } from '../../edit/harvesterhci.io.storage/index.vue'; export const LVM_DRIVER = 'lvm.driver.harvesterhci.io'; @@ -57,4 +57,8 @@ export default class HciStorageClass extends StorageClass { return this.$rootGetters['i18n/t'](key); } + + get isLonghornV2() { + return this.provisioner === LONGHORN_DRIVER && this.longhornVersion === DATA_ENGINE_V2; + } } diff --git a/pkg/harvester/models/kubevirt.io.virtualmachine.js b/pkg/harvester/models/kubevirt.io.virtualmachine.js index 7725e77c139..c420622642c 100644 --- a/pkg/harvester/models/kubevirt.io.virtualmachine.js +++ b/pkg/harvester/models/kubevirt.io.virtualmachine.js @@ -152,7 +152,7 @@ export default class VirtVm extends HarvesterResource { }, { action: 'takeVMSnapshot', - enabled: !!this.actions?.backup, + enabled: !!this.actions?.backup && !this.longhornV2Volumes.length, icon: 'icon icon-snapshot', label: this.t('harvester.action.vmSnapshot') }, @@ -595,16 +595,21 @@ export default class VirtVm extends HarvesterResource { return vmis.find(VMI => VMI.id === this.id); } - get encryptedVolumeType() { - const inStore = this.productInStore; - const pvcs = this.$rootGetters[`${ inStore }/all`](PVC); + get volumes() { + const pvcs = this.$rootGetters[`${ this.productInStore }/all`](PVC); const volumeClaimNames = this.spec.template.spec.volumes?.map(v => v.persistentVolumeClaim?.claimName).filter(v => !!v) || []; - const volumes = pvcs.filter(pvc => volumeClaimNames.includes(pvc.metadata.name)); + return pvcs.filter(pvc => volumeClaimNames.includes(pvc.metadata.name)); + } - if (volumes.every(vol => vol.isEncrypted)) { + get longhornV2Volumes() { + return this.volumes.filter((volume) => volume.storageClass.isLonghornV2); + } + + get encryptedVolumeType() { + if (this.volumes.every(vol => vol.isEncrypted)) { return 'all'; - } else if (volumes.some(vol => vol.isEncrypted)) { + } else if (this.volumes.some(vol => vol.isEncrypted)) { return 'partial'; } else { return 'none'; From 5596e68f00e7b80a2460256939f522a31e65b565 Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Tue, 8 Oct 2024 12:54:48 +0200 Subject: [PATCH 3/4] Code clean-up Signed-off-by: Francesco Torchia (cherry picked from commit 836a8780a906392afa3b83f2ae6a675dd80dace5) --- pkg/harvester/edit/harvesterhci.io.volume.vue | 3 +-- .../kubevirt.io.virtualmachine/VirtualMachineVolume/index.vue | 4 +--- .../VirtualMachineVolume/type/vmImage.vue | 4 +--- .../VirtualMachineVolume/type/volume.vue | 3 +-- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/pkg/harvester/edit/harvesterhci.io.volume.vue b/pkg/harvester/edit/harvesterhci.io.volume.vue index 28f6ee9ec00..9fd3a87cd0c 100644 --- a/pkg/harvester/edit/harvesterhci.io.volume.vue +++ b/pkg/harvester/edit/harvesterhci.io.volume.vue @@ -22,7 +22,6 @@ import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations import { STATE, NAME, AGE, NAMESPACE } from '@shell/config/table-headers'; import { LVM_DRIVER } from '../models/harvester/storage.k8s.io.storageclass'; import { DATA_ENGINE_V2 } from './harvesterhci.io.storage/index.vue'; -import { LONGHORN_DRIVER } from '@shell/models/persistentvolume'; export default { name: 'HarvesterVolume', @@ -225,7 +224,7 @@ export default { }, isLonghornV2() { - return this.value.storageClass?.provisioner === LONGHORN_DRIVER && this.value.storageClass?.longhornVersion === DATA_ENGINE_V2; + return this.value.storageClass?.isLonghornV2; } }, diff --git a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/index.vue b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/index.vue index 01b8b77305a..5472d47d5f0 100644 --- a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/index.vue +++ b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/index.vue @@ -18,8 +18,6 @@ import { SOURCE_TYPE } from '../../../config/harvester-map'; import { _VIEW, _EDIT, _CREATE } from '@shell/config/query-params'; import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../../../config/harvester'; import { PLUGIN_DEVELOPER, DEV } from '@shell/store/prefs'; -import { DATA_ENGINE_V2 } from '../../../edit/harvesterhci.io.storage/index.vue'; -import { LONGHORN_DRIVER } from '@shell/models/persistentvolume'; export default { components: { @@ -260,7 +258,7 @@ export default { }, isLonghornV2(volume) { - return volume?.pvc?.storageClass?.provisioner === LONGHORN_DRIVER && volume?.pvc?.storageClass?.longhornVersion === DATA_ENGINE_V2; + return volume?.pvc?.storageClass?.isLonghornV2; } }, }; diff --git a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/vmImage.vue b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/vmImage.vue index fa4c1887fee..801ff26ce98 100644 --- a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/vmImage.vue +++ b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/vmImage.vue @@ -12,8 +12,6 @@ import { formatSi, parseSi } from '@shell/utils/units'; import { VOLUME_TYPE, InterfaceOption } from '../../../../config/harvester-map'; import { _VIEW } from '@shell/config/query-params'; import { ucFirst } from '@shell/utils/string'; -import { LONGHORN_DRIVER } from '@shell/models/persistentvolume'; -import { DATA_ENGINE_V2 } from '../../../harvesterhci.io.storage/index.vue'; export default { name: 'HarvesterEditVMImage', @@ -117,7 +115,7 @@ export default { }, isLonghornV2() { - return this.value.pvc?.storageClass?.provisioner === LONGHORN_DRIVER && this.value.pvc?.storageClass?.longhornVersion === DATA_ENGINE_V2; + return this.value.pvc?.storageClass?.isLonghornV2; } }, diff --git a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/volume.vue b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/volume.vue index 3eb2e4fbc43..04117a669b8 100644 --- a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/volume.vue +++ b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/volume.vue @@ -12,7 +12,6 @@ import LabelValue from '@shell/components/LabelValue'; import { ucFirst } from '@shell/utils/string'; import { LVM_DRIVER } from '../../../../models/harvester/storage.k8s.io.storageclass'; import { DATA_ENGINE_V2 } from '../../../../edit/harvesterhci.io.storage/index.vue'; -import { LONGHORN_DRIVER } from '@shell/models/persistentvolume'; export default { name: 'HarvesterEditVolume', @@ -103,7 +102,7 @@ export default { }, isLonghornV2() { - return this.value.pvc?.storageClass?.provisioner === LONGHORN_DRIVER && this.value.pvc?.storageClass?.longhornVersion === DATA_ENGINE_V2; + return this.value.pvc?.storageClass?.isLonghornV2; } }, From 35bd7366a3933740f1196506677cb62b0c86121e Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Tue, 8 Oct 2024 13:34:26 +0200 Subject: [PATCH 4/4] Lint Signed-off-by: Francesco Torchia (cherry picked from commit 98c61611cd56256accb4b0c07c700828ad530fa8) --- pkg/harvester/list/kubevirt.io.virtualmachine.vue | 4 +++- pkg/harvester/models/kubevirt.io.virtualmachine.js | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/harvester/list/kubevirt.io.virtualmachine.vue b/pkg/harvester/list/kubevirt.io.virtualmachine.vue index 0ab2e5bc86b..2e498b5dcfe 100644 --- a/pkg/harvester/list/kubevirt.io.virtualmachine.vue +++ b/pkg/harvester/list/kubevirt.io.virtualmachine.vue @@ -2,7 +2,9 @@ import ConsoleBar from '../components/VMConsoleBar'; import ResourceTable from '@shell/components/ResourceTable'; import HarvesterVmState from '../formatters/HarvesterVmState'; -import { PVC, PV, NODE, POD, STORAGE_CLASS } from '@shell/config/types'; +import { + PVC, PV, NODE, POD, STORAGE_CLASS +} from '@shell/config/types'; import { STATE, AGE, NAME, NAMESPACE } from '@shell/config/table-headers'; import { HCI } from '../types'; import { allHash } from '@shell/utils/promise'; diff --git a/pkg/harvester/models/kubevirt.io.virtualmachine.js b/pkg/harvester/models/kubevirt.io.virtualmachine.js index c420622642c..b50358c5a1b 100644 --- a/pkg/harvester/models/kubevirt.io.virtualmachine.js +++ b/pkg/harvester/models/kubevirt.io.virtualmachine.js @@ -599,11 +599,12 @@ export default class VirtVm extends HarvesterResource { const pvcs = this.$rootGetters[`${ this.productInStore }/all`](PVC); const volumeClaimNames = this.spec.template.spec.volumes?.map(v => v.persistentVolumeClaim?.claimName).filter(v => !!v) || []; + return pvcs.filter(pvc => volumeClaimNames.includes(pvc.metadata.name)); } get longhornV2Volumes() { - return this.volumes.filter((volume) => volume.storageClass.isLonghornV2); + return this.volumes.filter(volume => volume.storageClass.isLonghornV2); } get encryptedVolumeType() {