diff --git a/roles/devscripts/defaults/main.yml b/roles/devscripts/defaults/main.yml index 3247581e4..19345ed7a 100644 --- a/roles/devscripts/defaults/main.yml +++ b/roles/devscripts/defaults/main.yml @@ -74,4 +74,5 @@ cifmw_devscripts_config_overrides: {} cifmw_devscripts_installer_timeout: 7200 # 2 hours cifmw_devscripts_etcd_slow_profile: true cifmw_devscripts_disable_console: false +cifmw_devscripts_ocp_vm_fstrim: "{{ cifmw_ocp_vm_fstrim | default(false) }}" cifmw_devscripts_cpu_passthrough: false diff --git a/roles/devscripts/tasks/300_post.yml b/roles/devscripts/tasks/300_post.yml index a7135ae60..909df3db7 100644 --- a/roles/devscripts/tasks/300_post.yml +++ b/roles/devscripts/tasks/300_post.yml @@ -46,6 +46,12 @@ - devscripts_deploy ansible.builtin.import_tasks: 340_etcd_slow_profile.yml +- name: Set daily fstrim timer on OCP nodes + when: cifmw_devscripts_ocp_vm_fstrim | bool + tags: + - devscripts_deploy + ansible.builtin.import_tasks: 342_fstrim_daily.yml + - name: Prepare for disk overlay configuration when: - not cifmw_devscripts_ocp_comply | bool diff --git a/roles/devscripts/tasks/342_fstrim_daily.yml b/roles/devscripts/tasks/342_fstrim_daily.yml new file mode 100644 index 000000000..e8ca8b1e6 --- /dev/null +++ b/roles/devscripts/tasks/342_fstrim_daily.yml @@ -0,0 +1,47 @@ +--- +# Copyright Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +- name: Apply daily fstrim timer MachineConfig for masters + kubernetes.core.k8s: + kubeconfig: "{{ cifmw_openshift_kubeconfig }}" + state: present + definition: + apiVersion: machineconfiguration.openshift.io/v1 + kind: MachineConfig + metadata: + labels: + machineconfiguration.openshift.io/role: master + name: 99-fstrim-daily-master + spec: + config: + ignition: + version: 3.2.0 + systemd: + units: + - name: fstrim.timer + enabled: true + contents: | + [Unit] + Description=Discard unused filesystem blocks daily + + [Timer] + OnCalendar=daily + AccuracySec=1h + Persistent=true + + [Install] + WantedBy=timers.target diff --git a/roles/libvirt_manager/README.md b/roles/libvirt_manager/README.md index 8e2010a12..4fa68ec46 100644 --- a/roles/libvirt_manager/README.md +++ b/roles/libvirt_manager/README.md @@ -46,6 +46,7 @@ Used for checking if: * `cifmw_libvirt_manager_vm_users`: (List[Dict]) Used to override the default list of users enabled in the vm. For its format, refers to cloud-init [documentation](https://cloudinit.readthedocs.io/en/latest/reference/modules.html#users-and-groups) about `users`. Defaults to `[]`. * `cifmw_libvirt_manager_extra_network_configuration`: (Dict) Extra network configuration in nmstate format for the hypervisor. This configuration is applied after creating the libvirt networks, so it can be used to create VLAN interfaces on the libvirt bridges. In addition to nmstate, it also supports a `cifmw_firewall_zone` hint in nmstate interfaces. Defaults to: `{}`. * `cifmw_libvirt_manager_radvd_networks`: (List[Dict]) List of networks to configure with radvd for IPv6 router advertisements. When defined, the `radvd` role will be included after network creation. Each network definition follows the format documented in the `radvd` role. Defaults to `[]`. +* `cifmw_libvirt_manager_ocp_vm_fstrim`: (Boolean) Add `discard='unmap'` to the libvirt disk driver for OCP VMs, allowing guest TRIM/discard operations to reclaim space on the host qcow2 files. Derives from the master variable `cifmw_ocp_vm_fstrim`. Defaults to `false`. ### `cifmw_libvirt_manager_default_gw_nets` parameter usage diff --git a/roles/libvirt_manager/defaults/main.yml b/roles/libvirt_manager/defaults/main.yml index e71fbf9f6..236a42dc9 100644 --- a/roles/libvirt_manager/defaults/main.yml +++ b/roles/libvirt_manager/defaults/main.yml @@ -92,3 +92,4 @@ cifmw_libvirt_manager_radvd_networks: [] cifmw_libvirt_manager_tmp_inv_file: "{{ ansible_user_dir }}/libvirt_inventory.ini" cifmw_libvirt_manager_dst_inv_file: "{{ ansible_user_dir }}/libvirt_inventory.yaml" +cifmw_libvirt_manager_ocp_vm_fstrim: "{{ cifmw_ocp_vm_fstrim | default(false) }}" diff --git a/roles/libvirt_manager/templates/domain.xml.j2 b/roles/libvirt_manager/templates/domain.xml.j2 index 024d391a6..b1e1eb5ad 100644 --- a/roles/libvirt_manager/templates/domain.xml.j2 +++ b/roles/libvirt_manager/templates/domain.xml.j2 @@ -42,7 +42,7 @@ /usr/libexec/qemu-kvm - + {% set disk_bus = vm_data.disk_bus | default('scsi') %} {% if disk_bus == 'scsi' %}