Skip to content

Commit

Permalink
No need to restart the VM if the config was not updated
Browse files Browse the repository at this point in the history
In order to apply the cpu mode="host-passthrough" config to the VM, one needs
to stop the VM first. That was the case before, every time. However, at
least on Fedora, the cpu mode="host-passthrough" is configured by
default and thus there is no need to actually update the config and then
restart the VM. This considerably speeds up the the process.

Note about the setup_minishift and start_minishift flag values - there
are four possible cases:
  1) 'setup_minishift == true and start_minishift == true' --- this will
     result in creating and initializing brand new minishift profile, which
     will be running after the init is done.

  2) 'setup_minishift == true and start_minishift == false' --- this will
     result in creating and initializing brand new minishift profile,
     but it will be stopped at the end (as start_minishift == false).
     It may well be started again by e.g. the os_temps role which
     usually comes after the minishift role.

  3) 'setup_minishift == false and start_minishift == true' --- this
     won't initialize (create) the VM at all. The VM is expected to be
     created before running contra-env-setup. The VM will, however, be
     started at the end (in case it's not already running).

  4) 'setup_minishift == false and start_minishift == false' --- this
     won't do minishift operations at all. This combination is useful
     for deploying into remote OpenShift clusters.
  • Loading branch information
Petr Široký committed Sep 6, 2018
1 parent ff9fc37 commit 118bca7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
28 changes: 23 additions & 5 deletions playbooks/roles/minishift/tasks/init_minishift.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
---
# start minishift
- name: "Initialization of minishift cluster with profile {{ profile }}"
shell: "{{ minishift_bin }} start --profile {{ profile }} --disk-size {{ disk_size }} --memory {{ memory }} --openshift-version {{ oc_version }} --iso-url file:///{{ minishift_dest_dir }}/minishift.iso"
shell: "{{ minishift_bin }} start --profile {{ profile }} --cpus {{ cpus }} --disk-size {{ disk_size }} --memory {{ memory }} --openshift-version {{ oc_version }} --iso-url file:///{{ minishift_dest_dir }}/minishift.iso"

- name: Wait for the cluster to come up completely
- name: "Check if <cpu mode=host-passthrough/> is already set"
find:
paths: "/etc/libvirt/qemu"
patterns: "{{ profile }}.xml"
contains: '\s*<cpu.*\smode=[\"\'']host-passthrough[\"\''].*/>'
register: minishift_vm_config_files
become: yes
when: (host_os == "linux")

- set_fact:
cpu_mode_not_configured: ((minishift_vm_config_files | default([])) | length == 0)

- name: "Wait for the cluster to come up completely"
pause:
minutes: 3
when: (host_os == "linux" and cpu_mode_not_configured|bool) or (start_minishift|bool == false)

- name: Stop the cluster
- name: "Stop the minishift profile {{ profile }}"
shell: "{{ minishift_bin }} stop --profile {{ profile }}"
when: (host_os == "linux" and cpu_mode_not_configured|bool) or (start_minishift|bool == false)

- name: Update the VM config
- name: "Update the minishift VM config"
lineinfile:
path: "/etc/libvirt/qemu/{{ profile }}.xml"
insertafter: '\s+</features>'
line: " <cpu mode='host-passthrough'/>"
become: yes
when: host_os == "linux"
when: (host_os == "linux") and (cpu_mode_not_configured|bool)

- name: "Start minishift profile {{ profile }} again if configured"
shell: "{{ minishift_bin }} start --profile {{ profile }} --cpus {{ cpus }} --disk-size {{ disk_size }} --memory {{ memory }} --openshift-version {{ oc_version }} --iso-url file:///{{ minishift_dest_dir }}/minishift.iso"
when: (host_os == "linux" and cpu_mode_not_configured|bool) and (start_minishift|bool == true)
2 changes: 1 addition & 1 deletion playbooks/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- { role: cleanup, when: run_cleanup|bool == true }
- role: create
- { role: prereqs, when: "run_prereqs|bool == true and setup_minishift|bool == true" }
- { role: minishift, when: "setup_minishift|bool == true and start_minishift == false" }
- { role: minishift, when: "setup_minishift|bool == true" }
- { role: os_temps, when: setup_containers|bool == true }
- { role: pipeline, when: setup_pipelines|bool == true }
- { role: playbook_hooks, when: setup_playbook_hooks|bool == true }

0 comments on commit 118bca7

Please sign in to comment.