Skip to content

Commit

Permalink
feat: ISO boot support for KVM agents - HCP (#341)
Browse files Browse the repository at this point in the history
Added support for ISO boot support for KVM agents - HCP 
Updated docs

---------

Signed-off-by: DAMISETTI-VEERABHADRARAO <[email protected]>
  • Loading branch information
veera-damisetti authored Oct 23, 2024
1 parent 47f1dca commit cb621ba
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 12 deletions.
9 changes: 5 additions & 4 deletions docs/set-variables-group-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,11 @@
**hcp.data_plane.vcpus** | vCPUs for compute nodes | 4
**hcp.data_plane.memory** | RAM for compute nodes | 16384
**hcp.data_plane.nameserver** | Nameserver for compute nodes | 192.168.10.1
**hcp.data_plane.storage.type** | Storage type for KVM guests qcow/dasd | qcow
**hcp.data_plane.storage.qcow.disk_size** | Disk size for kvm guests | 100G
**hcp.data_plane.storage.qcow.pool_path** | Storage pool path for creating disks | /home/images/
**hcp.data_plane.storage.dasd** | dasd disks for kvm guests | /disk
**hcp.data_plane.kvm.boot_method** | Boot method for booting agents. Supported methods: pxe, iso | pxe
**hcp.data_plane.kvm.storage.type** | Storage type for KVM guests qcow/dasd | qcow
**hcp.data_plane.kvm.storage.qcow.disk_size** | Disk size for kvm guests | 100G
**hcp.data_plane.kvm.storage.qcow.pool_path** | Storage pool path for creating disks | /home/images/
**hcp.data_plane.kvm.storage.dasd** | dasd disks for kvm guests | /disk
**hcp.data_plane.kvm.ip_params.static_ip.enabled** | true or false - use static IPs for agents using NMState | true
**hcp.data_plane.kvm.ip_params.static_ip.ip** | List of IP addresses for agents | 192.168.10.1
**hcp.data_plane.kvm.ip_params.static_ip.interface** | Interface for agents for configuring NMStateConfig | eth0
Expand Down
1 change: 1 addition & 0 deletions inventories/default/group_vars/hcp.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ hcp:
nameserver:

kvm:
boot_method: pxe # Supported methods : pxe, iso
storage:
type: qcow # Supported types: qcow, dasd
qcow:
Expand Down
8 changes: 5 additions & 3 deletions playbooks/create_hosted_cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@

- name: Configure httpd on bastion for hosting rootfs
hosts: bastion_hcp
roles:
- download_rootfs_hcp

tasks:
- name: Download rootfs image
include_role:
name: download_rootfs_hcp
when: ( hcp.data_plane.kvm.boot_method | lower != 'iso' and hcp.compute_node_type | lower == 'kvm' ) or hcp.compute_node_type | lower != 'kvm'
37 changes: 35 additions & 2 deletions roles/boot_agents_hcp/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
loop: "{{ range(hcp.data_plane.compute_count|int) | list }}"
when: hcp.data_plane.kvm.storage.type != 'dasd'

- name: Boot Agents
- name: Boot Agents with pxe artifacts
shell: |
{% if hcp.data_plane.kvm.ip_params.static_ip.enabled == true %}
mac_address=$(oc get NmStateConfig static-ip-nmstate-config-{{ hcp.control_plane.hosted_cluster_name }}-{{ item }} -n {{ hcp.control_plane.clusters_namespace }}-{{ hcp.control_plane.hosted_cluster_name }} -o json | jq -r '.spec.interfaces[] | .macAddress')
Expand Down Expand Up @@ -35,4 +35,37 @@
--extra-args "console=tty1 console=ttyS1,115200n8 coreos.inst.persistent-kargs=console=tty1 console=ttyS1,115200n8"
async: 3600
poll: 0
loop: "{{ range(hcp.data_plane.compute_count|int) | list }}"
loop: "{{ range(hcp.data_plane.compute_count|int) | list }}"
when: hcp.data_plane.kvm.boot_method | lower != 'iso'

- name: Boot Agents with iso
shell: |
{% if hcp.data_plane.kvm.ip_params.static_ip.enabled == true %}
mac_address=$(oc get NmStateConfig static-ip-nmstate-config-{{ hcp.control_plane.hosted_cluster_name }}-{{ item }} -n {{ hcp.control_plane.clusters_namespace }}-{{ hcp.control_plane.hosted_cluster_name }} -o json | jq -r '.spec.interfaces[] | .macAddress')
{% else %}
mac_address="{{ hcp.data_plane.kvm.ip_params.mac[item] }}"
{% endif %}
{% if hcp.data_plane.kvm.storage.type != "dasd" %}
disk_param="{{ hcp.data_plane.kvm.storage.qcow.pool_path }}{{ hcp.control_plane.hosted_cluster_name }}-agent{{ item }}.qcow2"
{% else %}
disk_param="{{ hcp.data_plane.kvm.storage.dasd[item] }}"
{% endif %}
virt-install \
--name "{{ hcp.control_plane.hosted_cluster_name }}-agent-{{ item }}" \
--autostart \
--memory="{{ hcp.data_plane.memory }}" \
--cpu host \
--vcpus="{{ hcp.data_plane.vcpus }}" \
--network network:{{ hcp.bastion_params.network_name }},mac=$mac_address \
--cdrom "/var/lib/libvirt/images/pxeboot/image.iso" \
--disk $disk_param \
--graphics none \
--noautoconsole \
--os-variant detect=on,require=off \
--wait=-1
async: 3600
poll: 0
loop: "{{ range(hcp.data_plane.compute_count|int) | list }}"
when: hcp.data_plane.kvm.boot_method | lower == 'iso'

2 changes: 1 addition & 1 deletion roles/boot_zvm_nodes_hcp/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@
register: agent_name

- name: Approve agents
shell: oc -n {{ hcp.control_plane.clusters_namespace }}-{{ hcp.control_plane.hosted_cluster_name }} patch agent {{ agent_name.stdout.split(' ')[0] }} -p '{"spec":{"approved":true,"hostname":"compute-{{ item }}.{{hcp.control_plane.hosted_cluster_name }}.{{ hcp.control_plane.hcp.basedomain }}"}}' --type merge
shell: oc -n {{ hcp.control_plane.clusters_namespace }}-{{ hcp.control_plane.hosted_cluster_name }} patch agent {{ agent_name.stdout.split(' ')[0] }} -p '{"spec":{"approved":true,"hostname":"compute-{{ item }}.{{hcp.control_plane.hosted_cluster_name }}.{{ hcp.control_plane.basedomain }}"}}' --type merge

6 changes: 4 additions & 2 deletions roles/delete_resources_bastion_hcp/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
until: managedcluster.rc != 0
retries: 50
delay: 25
when: hcp.mce.delete == true
ignore_errors: yes

- fail:
Expand All @@ -115,6 +114,7 @@

- name: Disable local-cluster component in MCE
command: oc patch mce {{ hcp.mce.instance_name }} -p '{"spec":{"overrides":{"components":[{"name":"local-cluster","enabled":false}]}}}' --type merge
when: hcp.mce.delete == true

- name: Wait for local-cluster components to be deleted
shell: oc get ns local-cluster
Expand All @@ -127,7 +127,9 @@

- fail:
msg: "local-cluster namespace is still present"
when: localcluster.rc == 0 and localcluster.attempts >= 40
when:
- hcp.mce.delete == true
- localcluster.rc == 0 and localcluster.attempts >= 40

- name: Delete AgentServiceConfig
k8s:
Expand Down
8 changes: 8 additions & 0 deletions roles/delete_resources_kvm_host_hcp/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@
file:
path: /var/lib/libvirt/images/pxeboot/initrd.img
state: absent
when: ( hcp.data_plane.kvm.boot_method | lower != 'iso' and hcp.compute_node_type | lower == 'kvm' ) or hcp.compute_node_type | lower != 'kvm'

- name: Delete kernel.img
file:
path: /var/lib/libvirt/images/pxeboot/kernel.img
state: absent
when: ( hcp.data_plane.kvm.boot_method | lower != 'iso' and hcp.compute_node_type | lower == 'kvm' ) or hcp.compute_node_type | lower != 'kvm'

- name: Delete iso
file:
path: /var/lib/libvirt/images/pxeboot/image.iso
state: absent
when: hcp.data_plane.kvm.boot_method | lower == 'iso' and hcp.compute_node_type | lower == 'kvm'

- name: Destroy bastion
command: virsh destroy {{ hcp.control_plane.hosted_cluster_name }}-bastion
Expand Down
16 changes: 16 additions & 0 deletions roles/setup_for_agents_hcp/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,38 @@
- name: Get URL for initrd.img
shell: oc -n "{{ hcp.control_plane.clusters_namespace }}-{{ hcp.control_plane.hosted_cluster_name }}" get InfraEnv "{{ hcp.control_plane.hosted_cluster_name }}" -ojsonpath="{.status.bootArtifacts.initrd}"
register: initrd
when: ( hcp.data_plane.kvm.boot_method | lower != 'iso' and hcp.compute_node_type | lower == 'kvm' ) or hcp.compute_node_type | lower != 'kvm'

- name: Download initrd.img
get_url:
url: "{{ initrd.stdout }}"
dest: /var/lib/libvirt/images/pxeboot/initrd.img
validate_certs: false
when: ( hcp.data_plane.kvm.boot_method | lower != 'iso' and hcp.compute_node_type | lower == 'kvm' ) or hcp.compute_node_type | lower != 'kvm'

- name: Get URL for kernel.img
shell: oc -n "{{ hcp.control_plane.clusters_namespace }}-{{ hcp.control_plane.hosted_cluster_name }}" get InfraEnv "{{ hcp.control_plane.hosted_cluster_name }}" -ojsonpath="{.status.bootArtifacts.kernel}"
register: kernel
when: ( hcp.data_plane.kvm.boot_method | lower != 'iso' and hcp.compute_node_type | lower == 'kvm' ) or hcp.compute_node_type | lower != 'kvm'

- name: Download kernel.img
get_url:
url: "{{ kernel.stdout }}"
dest: /var/lib/libvirt/images/pxeboot/kernel.img
validate_certs: false
when: ( hcp.data_plane.kvm.boot_method | lower != 'iso' and hcp.compute_node_type | lower == 'kvm' ) or hcp.compute_node_type | lower != 'kvm'

- name: Get URL for ISO
shell: oc -n "{{ hcp.control_plane.clusters_namespace }}-{{ hcp.control_plane.hosted_cluster_name }}" get InfraEnv "{{ hcp.control_plane.hosted_cluster_name }}" -ojsonpath="{.status.isoDownloadURL}"
register: iso
when: hcp.data_plane.kvm.boot_method | lower == 'iso' and hcp.compute_node_type | lower == 'kvm'

- name: Download ISO image
get_url:
url: "{{ iso.stdout }}"
dest: /var/lib/libvirt/images/pxeboot/image.iso
validate_certs: false
when: hcp.data_plane.kvm.boot_method | lower == 'iso' and hcp.compute_node_type | lower == 'kvm'

- name: Generate param files
template:
Expand Down

0 comments on commit cb621ba

Please sign in to comment.