From 46516f257f1e268e6bc722036244e1f9688db613 Mon Sep 17 00:00:00 2001 From: Wolfgang Kulhanek Date: Thu, 12 Nov 2026 13:56:24 +0100 Subject: [PATCH 1/2] ocp4_workload_openshift_virtualization: set the boot source format in both directions ocp4_workload_openshift_virtualization_boot_sources_snapshot defaulted to true but only did something when false, patching the StorageProfile to pvc. With true the role patched nothing and the cluster silently kept CDI's own default of pvc, so every VM cloned from a boot source first had to snapshot the source PVC. On AWS EBS that is 13-15 minutes per VM; with the snapshot format set it is under 90 seconds. Run the block unconditionally and set the format from the variable. Also replace default_sc[0] with first/default so the existing 'no default storage class' abort reports its message instead of raising an index error, now that the block runs on every deployment. --- .../defaults/main.yml | 3 +++ .../tasks/workload.yml | 21 +++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/roles/ocp4_workload_openshift_virtualization/defaults/main.yml b/roles/ocp4_workload_openshift_virtualization/defaults/main.yml index 4997397..563bf2a 100644 --- a/roles/ocp4_workload_openshift_virtualization/defaults/main.yml +++ b/roles/ocp4_workload_openshift_virtualization/defaults/main.yml @@ -27,6 +27,9 @@ ocp4_workload_openshift_virtualization_workload_tolerations: [] # operator: Exists # Use Snapshots for boot sources - which is the default +# The StorageProfile of the default storage class is patched either way, as CDI +# itself defaults to pvc. With pvc every VM cloned from a boot source first has +# to snapshot the source PVC, which on AWS EBS takes minutes per VM. # 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 diff --git a/roles/ocp4_workload_openshift_virtualization/tasks/workload.yml b/roles/ocp4_workload_openshift_virtualization/tasks/workload.yml index 14065e0..564fd17 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 (default) or as PVCs, the latter + # for deployments on CNV with external Ceph. CDI defaults to pvc, so the + # snapshot format has to be set explicitly too - otherwise every VM cloned from + # a boot source first snapshots the source PVC, which on AWS EBS costs minutes. + # 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 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 From 7fd3dc2d927b98a06a71c6d3a8685c4ab07c374e Mon Sep 17 00:00:00 2001 From: Wolfgang Kulhanek Date: Thu, 12 Nov 2026 14:08:38 +0100 Subject: [PATCH 2/2] ocp4_workload_openshift_virtualization: make the boot source format opt-in Default the variable to null so the StorageProfile is left alone unless a config asks for a format. Flipping the default either way would have moved the 43 catalog items that never set it into an active branch: - true for all would patch them to snapshot - false for all would patch them to pvc and, through the template, create HyperConverged with enableCommonBootImageImport disabled With null they keep today's behaviour exactly - no StorageProfile patch and the import enabled at creation. The two items that set false are unaffected. Items that want fast clones on CSI storage opt in with true. --- .../defaults/main.yml | 16 ++++++++-------- .../tasks/workload.yml | 8 ++++---- .../templates/hyperconverged.yaml.j2 | 9 ++++++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/roles/ocp4_workload_openshift_virtualization/defaults/main.yml b/roles/ocp4_workload_openshift_virtualization/defaults/main.yml index 563bf2a..bf2aa2f 100644 --- a/roles/ocp4_workload_openshift_virtualization/defaults/main.yml +++ b/roles/ocp4_workload_openshift_virtualization/defaults/main.yml @@ -26,14 +26,14 @@ ocp4_workload_openshift_virtualization_workload_tolerations: [] # - key: metal # operator: Exists -# Use Snapshots for boot sources - which is the default -# The StorageProfile of the default storage class is patched either way, as CDI -# itself defaults to pvc. With pvc every VM cloned from a boot source first has -# to snapshot the source PVC, which on AWS EBS takes minutes per VM. -# 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 564fd17..54aebc7 100644 --- a/roles/ocp4_workload_openshift_virtualization/tasks/workload.yml +++ b/roles/ocp4_workload_openshift_virtualization/tasks/workload.yml @@ -74,13 +74,13 @@ retries: "{{ ocp4_workload_openshift_virtualization_hco_wait_retries }}" delay: "{{ ocp4_workload_openshift_virtualization_hco_wait_delay }}" - # Boot sources are stored as VolumeSnapshots (default) or as PVCs, the latter - # for deployments on CNV with external Ceph. CDI defaults to pvc, so the - # snapshot format has to be set explicitly too - otherwise every VM cloned from - # a boot source first snapshots the source PVC, which on AWS EBS costs minutes. + # 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: diff --git a/roles/ocp4_workload_openshift_virtualization/templates/hyperconverged.yaml.j2 b/roles/ocp4_workload_openshift_virtualization/templates/hyperconverged.yaml.j2 index 34f1545..cdd83e8 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 %}