Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions roles/ocp4_workload_openshift_virtualization/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
wkulhanek marked this conversation as resolved.
Resolved
# 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
Expand Down
21 changes: 12 additions & 9 deletions roles/ocp4_workload_openshift_virtualization/tasks/workload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand All @@ -107,15 +109,16 @@
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
kind: StorageProfile
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"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Loading