diff --git a/roles/ocp4_workload_openshift_virtualization/defaults/main.yml b/roles/ocp4_workload_openshift_virtualization/defaults/main.yml index 49973972..bf2aa2f4 100644 --- a/roles/ocp4_workload_openshift_virtualization/defaults/main.yml +++ b/roles/ocp4_workload_openshift_virtualization/defaults/main.yml @@ -26,11 +26,14 @@ ocp4_workload_openshift_virtualization_workload_tolerations: [] # - key: metal # operator: Exists -# Use Snapshots for boot sources - which is the default -# For deployments on top of CNV with Ceph set to false -# When set to false CNV is configured to use PVCs for boot sources -# which elminiates VolumeSnapshots without associated PVCs -ocp4_workload_openshift_virtualization_boot_sources_snapshot: true +# Boot source format for the StorageProfile of the default storage class. +# Unset: do not touch the StorageProfile, CDI picks the format itself (pvc). +# true: use VolumeSnapshots. Recommended on CSI storage - with pvc every VM +# cloned from a boot source first snapshots the source PVC, which on +# AWS EBS takes minutes per VM instead of seconds. +# false: use PVCs. For deployments on top of CNV with Ceph, as it eliminates +# VolumeSnapshots without associated PVCs. +ocp4_workload_openshift_virtualization_boot_sources_snapshot: ~ # For AWS it is possible to use KubeVirt without a metal node # For that the subscription for the operator needs to have special config diff --git a/roles/ocp4_workload_openshift_virtualization/tasks/workload.yml b/roles/ocp4_workload_openshift_virtualization/tasks/workload.yml index 14065e05..54aebc78 100644 --- a/roles/ocp4_workload_openshift_virtualization/tasks/workload.yml +++ b/roles/ocp4_workload_openshift_virtualization/tasks/workload.yml @@ -74,11 +74,13 @@ retries: "{{ ocp4_workload_openshift_virtualization_hco_wait_retries }}" delay: "{{ ocp4_workload_openshift_virtualization_hco_wait_delay }}" - # For deployments on CNV with external Ceph use PVCs for boot image snapshots - # HyperConverged must have been created with .spec.enableCommonBootImageImport: false - # See template for that logic - - name: Set boot sources to use PVCs - when: not ocp4_workload_openshift_virtualization_boot_sources_snapshot | bool + # Boot sources are stored as VolumeSnapshots or as PVCs, the latter for + # deployments on CNV with external Ceph. Left unset the StorageProfile is not + # touched at all and CDI picks the format itself. + # For pvc, HyperConverged must have been created with + # .spec.enableCommonBootImageImport: false - see template for that logic. + - name: Set the boot source format on the default storage class + when: ocp4_workload_openshift_virtualization_boot_sources_snapshot is not none block: - name: Get all available storage classes kubernetes.core.k8s_info: @@ -93,7 +95,7 @@ - name: Find default storage class ansible.builtin.set_fact: - _ocp4_workload_openshift_virtualization_default_storage_class: "{{ default_sc[0] }}" + _ocp4_workload_openshift_virtualization_default_storage_class: "{{ default_sc | first | default('', true) }}" vars: default_sc: "{{ r_storageclasses.resources | json_query(query_sc) }}" query_sc: "[?metadata.annotations.\"storageclass.kubernetes.io/is-default-class\" == 'true'].metadata.name" @@ -107,7 +109,7 @@ ansible.builtin.debug: msg: "Default storage class: {{ _ocp4_workload_openshift_virtualization_default_storage_class }}" - - name: Patch the storage profile matching the default storage class to use pvc instead of snapshot + - name: Patch the storage profile matching the default storage class with the boot source format kubernetes.core.k8s: state: patched api_version: cdi.kubevirt.io/v1beta1 @@ -115,7 +117,8 @@ name: "{{ _ocp4_workload_openshift_virtualization_default_storage_class }}" definition: spec: - dataImportCronSourceFormat: pvc + dataImportCronSourceFormat: >- + {{ 'snapshot' if ocp4_workload_openshift_virtualization_boot_sources_snapshot | bool else 'pvc' }} - name: If we are using Hosted Control Planes, it is needed to set default accessMode, volumeMode and cloneStrategy when: _ocp4_workload_openshift_virtualization_default_storage_class == "kubevirt-csi-infra-default" @@ -132,7 +135,7 @@ volumeMode: Block cloneStrategy: copy - - name: Finally patch HyperConverged to import boot sources now using PVCs + - name: Finally patch HyperConverged to import boot sources now the format is set kubernetes.core.k8s: state: patched api_version: hco.kubevirt.io/v1beta1 diff --git a/roles/ocp4_workload_openshift_virtualization/templates/hyperconverged.yaml.j2 b/roles/ocp4_workload_openshift_virtualization/templates/hyperconverged.yaml.j2 index 34f15450..cdd83e84 100644 --- a/roles/ocp4_workload_openshift_virtualization/templates/hyperconverged.yaml.j2 +++ b/roles/ocp4_workload_openshift_virtualization/templates/hyperconverged.yaml.j2 @@ -11,8 +11,11 @@ spec: tolerations: {{ ocp4_workload_openshift_virtualization_workload_tolerations | to_yaml }} {% endif %} -{% if ocp4_workload_openshift_virtualization_boot_sources_snapshot | default(true) | bool %} - enableCommonBootImageImport: true -{% else %} +{# Only an explicit false defers the import, so workload.yml can set the pvc #} +{# format on the StorageProfile first and enable the import afterwards. #} +{% set _boot_sources = ocp4_workload_openshift_virtualization_boot_sources_snapshot | default(none) %} +{% if _boot_sources is not none and not (_boot_sources | bool) %} enableCommonBootImageImport: false +{% else %} + enableCommonBootImageImport: true {% endif %}