diff --git a/roles/devscripts/defaults/main.yml b/roles/devscripts/defaults/main.yml index 3247581e4..b8021732f 100644 --- a/roles/devscripts/defaults/main.yml +++ b/roles/devscripts/defaults/main.yml @@ -59,6 +59,7 @@ cifmw_devscripts_dry_run: false cifmw_devscripts_enable_ocp_nodes_host_routing: false cifmw_devscripts_enable_iscsi_on_ocp_nodes: false cifmw_devscripts_enable_multipath_on_ocp_nodes: false +cifmw_devscripts_enable_disk_discard: false cifmw_devscripts_remove_libvirt_net_default: false cifmw_devscripts_use_static_ip_addr: false diff --git a/roles/devscripts/tasks/300_post.yml b/roles/devscripts/tasks/300_post.yml index a7135ae60..3363408dd 100644 --- a/roles/devscripts/tasks/300_post.yml +++ b/roles/devscripts/tasks/300_post.yml @@ -53,3 +53,15 @@ tags: - devscripts_deploy ansible.builtin.include_tasks: 310_prepare_overlay.yml + +- name: Enable discard on OCP master VM disks + when: + - cifmw_devscripts_enable_disk_discard | bool + - not cifmw_devscripts_ocp_comply | bool + - not cifmw_devscripts_ocp_online | bool + tags: + - devscripts_deploy + ansible.builtin.include_tasks: 350_disk_discard.yml + loop: "{{ range(0, cifmw_devscripts_config.num_masters | int) | list }}" + loop_control: + loop_var: _cifmw_devscripts_master_idx diff --git a/roles/devscripts/tasks/350_disk_discard.yml b/roles/devscripts/tasks/350_disk_discard.yml new file mode 100644 index 000000000..1c551fd34 --- /dev/null +++ b/roles/devscripts/tasks/350_disk_discard.yml @@ -0,0 +1,63 @@ +--- +# 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. + +# Called once per master index via include_tasks loop in 300_post.yml. +# Loop variable: _cifmw_devscripts_master_idx + +- name: Set master VM name fact + ansible.builtin.set_fact: + _cifmw_devscripts_master_vm: >- + {{ cifmw_devscripts_config.cluster_name }}-master-{{ _cifmw_devscripts_master_idx }} + +- name: Add discard=unmap to master-{{ _cifmw_devscripts_master_idx }} persistent disk config + # virt-xml updates the persistent domain XML without requiring the VM to be shut down. + # device=disk filters to storage disks only, excluding cdrom/ISO devices. + # The change takes effect on next boot. + ansible.builtin.command: + cmd: >- + virt-xml {{ _cifmw_devscripts_master_vm }} + --edit device=disk + --disk discard=unmap + --define + +- name: Reboot master-{{ _cifmw_devscripts_master_idx }} to apply disk config change + ansible.builtin.command: + cmd: virsh reboot {{ _cifmw_devscripts_master_vm }} + +- name: Wait for master-{{ _cifmw_devscripts_master_idx }} to return to Ready + vars: + _kubeconfig: >- + {{ + ( + cifmw_devscripts_repo_dir, + 'ocp', + cifmw_devscripts_config.cluster_name, + 'auth', + 'kubeconfig' + ) | ansible.builtin.path_join + }} + # OCP node names are master-N, not -master-N. + ansible.builtin.command: + cmd: >- + oc wait node/master-{{ _cifmw_devscripts_master_idx }} + --for=condition=Ready + --timeout=300s + environment: + KUBECONFIG: "{{ _kubeconfig }}" + retries: 3 + delay: 10 + register: _cifmw_devscripts_node_wait + until: _cifmw_devscripts_node_wait.rc == 0