From 6c9f22c771ccb395cb83ce61b3c7fb84c6967004 Mon Sep 17 00:00:00 2001 From: Aviv Turgeman Date: Wed, 20 Sep 2023 12:18:04 +0300 Subject: [PATCH] CNV-32995: Align volume name 'rootdisk' convention Signed-off-by: Aviv Turgeman --- src/utils/components/CloneTemplateModal/utils.ts | 3 ++- src/utils/constants/constants.ts | 2 ++ .../catalog/CreateFromInstanceTypes/utils/utils.ts | 5 +++-- src/views/catalog/templatescatalog/tests/mocks.ts | 10 ++++++---- src/views/templates/actions/editBootSource.ts | 4 ++-- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/utils/components/CloneTemplateModal/utils.ts b/src/utils/components/CloneTemplateModal/utils.ts index 8f0914a09..175ad8864 100644 --- a/src/utils/components/CloneTemplateModal/utils.ts +++ b/src/utils/components/CloneTemplateModal/utils.ts @@ -5,13 +5,14 @@ import { V1beta1DataVolumeSourcePVC, V1beta1DataVolumeSpec, } from '@kubevirt-ui/kubevirt-api/kubevirt'; +import { ROOTDISK } from '@kubevirt-utils/constants/constants'; import { getTemplateVirtualMachineObject } from '@kubevirt-utils/resources/template'; import { getDataVolumeTemplates, getVolumes } from '@kubevirt-utils/resources/vm'; import { k8sCreate } from '@openshift-console/dynamic-plugin-sdk'; const getBootSourceDataVolumeTemplate = (template: V1Template) => { const vm = getTemplateVirtualMachineObject(template); - const rootVolume = getVolumes(vm)?.find((volume) => volume.name === 'rootdisk'); + const rootVolume = getVolumes(vm)?.find((volume) => volume.name === ROOTDISK); if (rootVolume?.dataVolume?.name) return getDataVolumeTemplates(vm)?.find( diff --git a/src/utils/constants/constants.ts b/src/utils/constants/constants.ts index 167e316af..f6e842708 100644 --- a/src/utils/constants/constants.ts +++ b/src/utils/constants/constants.ts @@ -8,3 +8,5 @@ export const OPENSHIFT_SRIOV_NETWORK_OPERATOR_NS = 'openshift-sriov-network-oper export const OPENSHIFT_MULTUS_NS = 'openshift-multus'; export const VENDOR_LABEL = 'instancetype.kubevirt.io/vendor'; + +export const ROOTDISK = 'rootdisk'; diff --git a/src/views/catalog/CreateFromInstanceTypes/utils/utils.ts b/src/views/catalog/CreateFromInstanceTypes/utils/utils.ts index 982c21893..47f6c94ca 100644 --- a/src/views/catalog/CreateFromInstanceTypes/utils/utils.ts +++ b/src/views/catalog/CreateFromInstanceTypes/utils/utils.ts @@ -7,6 +7,7 @@ import { V1VirtualMachine } from '@kubevirt-ui/kubevirt-api/kubevirt'; import { convertUserDataObjectToYAML } from '@kubevirt-utils/components/CloudinitModal/utils/cloudinit-utils'; import { ACTIVATION_KEY } from '@kubevirt-utils/components/CloudinitModal/utils/consts'; import { addSecretToVM } from '@kubevirt-utils/components/SSHSecretSection/utils/utils'; +import { ROOTDISK } from '@kubevirt-utils/constants/constants'; import { RHELAutomaticSubscriptionData } from '@kubevirt-utils/hooks/useRHELAutomaticSubscription/utils/types'; import { isBootableVolumePVCKind } from '@kubevirt-utils/resources/bootableresources/helpers'; import { getName, getNamespace } from '@kubevirt-utils/resources/shared'; @@ -122,7 +123,7 @@ export const generateVM = ( disk: { bus: 'virtio', }, - name: `${virtualmachineName}-disk`, + name: ROOTDISK, }, { disk: { @@ -136,7 +137,7 @@ export const generateVM = ( volumes: [ { dataVolume: { name: `${virtualmachineName}-volume` }, - name: `${virtualmachineName}-disk`, + name: ROOTDISK, }, { cloudInitConfigDrive: { diff --git a/src/views/catalog/templatescatalog/tests/mocks.ts b/src/views/catalog/templatescatalog/tests/mocks.ts index 31a50d0f8..aef2e8514 100644 --- a/src/views/catalog/templatescatalog/tests/mocks.ts +++ b/src/views/catalog/templatescatalog/tests/mocks.ts @@ -1,3 +1,5 @@ +import { ROOTDISK } from '@kubevirt-utils/constants/constants'; + export const containerTemplateMock = { apiVersion: 'template.openshift.io/v1', kind: 'Template', @@ -43,7 +45,7 @@ export const containerTemplateMock = { disk: { bus: 'virtio', }, - name: 'rootdisk', + name: ROOTDISK, }, ], interfaces: [ @@ -72,7 +74,7 @@ export const containerTemplateMock = { containerDisk: { image: 'fooContainer', }, - name: 'rootdisk', + name: ROOTDISK, }, ], }, @@ -130,7 +132,7 @@ export const urlTemplateMock = { disk: { bus: 'virtio', }, - name: 'rootdisk', + name: ROOTDISK, }, ], interfaces: [ @@ -160,7 +162,7 @@ export const urlTemplateMock = { // eslint-disable-next-line no-template-curly-in-string name: 'url-template-rootdisk', }, - name: 'rootdisk', + name: ROOTDISK, }, ], }, diff --git a/src/views/templates/actions/editBootSource.ts b/src/views/templates/actions/editBootSource.ts index eaabed69b..639d5e0f1 100644 --- a/src/views/templates/actions/editBootSource.ts +++ b/src/views/templates/actions/editBootSource.ts @@ -12,7 +12,7 @@ import { V1beta1DataVolumeSpec, V1DataVolumeTemplateSpec, } from '@kubevirt-ui/kubevirt-api/kubevirt'; -import { DEFAULT_NAMESPACE } from '@kubevirt-utils/constants/constants'; +import { DEFAULT_NAMESPACE, ROOTDISK } from '@kubevirt-utils/constants/constants'; import { getTemplateVirtualMachineObject, poorManProcess, @@ -64,7 +64,7 @@ const getRootDiskDataVolumeTemplate = ( ): undefined | V1DataVolumeTemplateSpec => { const vm = getTemplateVirtualMachineObject(template); - const rootVolume = getVolumes(vm)?.find((volume) => volume.name === 'rootdisk'); + const rootVolume = getVolumes(vm)?.find((volume) => volume.name === ROOTDISK); return vm?.spec?.dataVolumeTemplates?.find( (dataVolumeTemplate) => rootVolume?.dataVolume?.name === dataVolumeTemplate?.metadata?.name,