Skip to content

Commit

Permalink
Add support for Leap Micro and combustion
Browse files Browse the repository at this point in the history
In order to support leap micro we need combustion support in the libvirt
provider. This requires this pull request:

dmacvicar/terraform-provider-libvirt#1068
  • Loading branch information
cbosdo authored and jordimassaguerpla committed Mar 6, 2024
1 parent 12c4a29 commit 2a5e15f
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 17 deletions.
1 change: 1 addition & 0 deletions backend_modules/libvirt/base/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ locals {
slemicro54-ign = "${var.use_mirror_images ? "http://${var.mirror}" : "http://download.opensuse.org"}/repositories/systemsmanagement:/sumaform:/images:/microos/images_54/SLE-Micro.x86_64-sumaform.qcow2"
slemicro55o = "${var.use_mirror_images ? "http://${var.mirror}" : "http://download.opensuse.org"}/repositories/systemsmanagement:/sumaform:/images:/microos/images_55/SLE-Micro.x86_64-sumaform.qcow2"
suma43VM-ign = "${var.use_mirror_images ? "http://${var.mirror}" : "http://download.suse.de"}/ibs/Devel:/Galaxy:/Manager:/4.3/images/SUSE-Manager-Server.x86_64-KVM.qcow2"
leapmicro55o = "${var.use_mirror_images ? "http://${var.mirror}" : "https://download.opensuse.org"}/distribution/leap-micro/5.5/appliances/openSUSE-Leap-Micro.x86_64-Default-qcow.qcow2"
}
pool = lookup(var.provider_settings, "pool", "default")
network_name = lookup(var.provider_settings, "network_name", "default")
Expand Down
52 changes: 52 additions & 0 deletions backend_modules/libvirt/host/combustion
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
# combustion: network

# Redirect output to the console
exec > >(exec tee -a /dev/tty0) 2>&1

# Set linux as password for root
echo 'root:$6$3aQC9rrDLHiTf1yR$NoKe9tko0kFIpu0rQ2y/OzOOtbVvs0Amr2bx0T4cGf6aq8PG74EmVy8lSDJdbLVVFpOSzwELWyReRCiPHa7DG0' | chpasswd -e

# Add a public ssh key and enable sshd
systemctl enable sshd.service

# Add the GPG keys
${ gpg_keys }

# Add repositories
zypper ar http://${ use_mirror_images ? mirror : "download.opensuse.org" }/repositories/SUSE:/CA/15.5/ ca_suse
%{ if container_server || container_proxy }
zypper ar http://${ use_mirror_images ? mirror : "download.opensuse.org" }/repositories/systemsmanagement:/Uyuni:/Master:/ContainerUtils/openSUSE_Leap_Micro_5.5/ container_utils
%{ endif }

%{ if testsuite }
zypper ar http://${ use_mirror_images ? mirror : "download.opensuse.org" }/repositories/systemsmanagement:/Uyuni:/Test-Packages:/Pool/rpm/ test_packages_pool
%{ endif }

# Install packages
PACKAGES="qemu-guest-agent avahi ca-certificates"
%{ if container_server }
PACKAGES="\$PACKAGES bash-completion mgradm mgrctl mgradm-bash-completion mgrctl-bash-completion"
%{ endif }
%{ if container_runtime == "podman" }
PACKAGES="\$PACKAGES podman netavark"
%{ endif }

%{ if container_runtime == "k3s" }
PACKAGES="\$PACKAGES helm"
%{ endif }

%{ if container_proxy }
PACKAGES="\$PACKAGES bash-completion mgrpxy"
%{ else }
PACKAGES="\$PACKAGES salt-minion"
%{ endif }

%{ if testsuite }
PACKAGES="\$PACKAGES andromeda-dummy milkyway-dummy virgo-dummy wget timezone aaa_base-extras"
%{ endif }
zypper --non-interactive install \$PACKAGES

# Leave a marker
echo "Configured with combustion" > /etc/issue.d/combustion

33 changes: 30 additions & 3 deletions backend_modules/libvirt/host/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ locals {
manufacturer = lookup(var.provider_settings, "manufacturer", "Intel")
product = lookup(var.provider_settings, "product", "Genuine")
x86_64_v2_images = ["almalinux9o", "libertylinux9o", "oraclelinux9o", "rocky9o"]
combustion_images = ["leapmicro55o"]
gpg_keys = [
for key in fileset("salt/default/gpg_keys/", "*.key"): {
path = "/etc/gpg_keys/${key}"
Expand All @@ -13,6 +14,9 @@ locals {
permissions = "0700"
}
]
container_runtime = lookup(var.grains, "container_runtime", "")

combustion = contains(local.combustion_images, var.image)
provider_settings = merge({
memory = 1024
vcpu = 1
Expand Down Expand Up @@ -41,8 +45,8 @@ locals {
var.provider_settings,
contains(var.roles, "virthost") ? { cpu_model = "host-passthrough", xslt = file("${path.module}/virthost.xsl") } : {},
contains(var.roles, "pxe_boot") ? { xslt = templatefile("${path.module}/pxe_boot.xsl", { manufacturer = local.manufacturer, product = local.product }) } : {})
cloud_init = length(regexall("o$", var.image)) > 0
ignition = length(regexall("-ign$", var.image)) > 0
cloud_init = length(regexall("o$", var.image)) > 0 && !contains(local.combustion_images, var.image)
ignition = length(regexall("-ign$", var.image)) > 0
}

data "template_file" "user_data" {
Expand All @@ -66,6 +70,28 @@ data "template_file" "network_config" {
}
}

data "template_file" "combustion" {
template = file("${path.module}/combustion")
vars = {
gpg_keys = join("\n", [for key in local.gpg_keys :
"mkdir -p `dirname ${key.path}` && echo ${key.content} | base64 -d >${key.path} && rpm --import ${key.path}"
])
use_mirror_images = var.base_configuration["use_mirror_images"]
mirror = var.base_configuration["mirror"]
container_server = contains(var.roles, "server_containerized")
container_proxy = contains(var.roles, "proxy_containerized")
container_runtime = local.container_runtime
testsuite = lookup(var.base_configuration, "testsuite", false)
}
}

resource "libvirt_combustion" "combustion_disk" {
name = "${local.resource_name_prefix}${var.quantity > 1 ? "-${count.index + 1}" : ""}-combustion-disk"
pool = var.base_configuration["pool"]
content = data.template_file.combustion.rendered
count = local.combustion ? var.quantity : 0
}

data "template_file" "ignition" {
template = file("${path.module}/config.ign")
}
Expand Down Expand Up @@ -135,7 +161,8 @@ resource "libvirt_domain" "domain" {
}

cloudinit = length(libvirt_cloudinit_disk.cloudinit_disk) == var.quantity ? libvirt_cloudinit_disk.cloudinit_disk[count.index].id : null
coreos_ignition = length(libvirt_ignition.ignition_disk) == var.quantity ? libvirt_ignition.ignition_disk[count.index].id : null
coreos_ignition = length(libvirt_ignition.ignition_disk) == var.quantity ? libvirt_ignition.ignition_disk[count.index].id : length(libvirt_combustion.combustion_disk) == var.quantity ? libvirt_combustion.combustion_disk[count.index].id : null
fw_cfg_name = local.combustion ? "opt/org.opensuse.combustion/script" : null

dynamic "network_interface" {
for_each = slice(
Expand Down
2 changes: 1 addition & 1 deletion modules/server_containerized/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
variable "images" {
default = {
"head" = "slemicro55o"
"uyuni-master" = "opensuse155o"
"uyuni-master" = "leapmicro55o"
"uyuni-released" = "opensuse155o"
"uyuni-pr" = "opensuse155o"
}
Expand Down
2 changes: 1 addition & 1 deletion salt/server_containerized/initial_content.sls
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ first_user_set_password:
- name: mgrctl exec 'echo -e "{{ server_password }}\\n{{ server_password }}" | satpasswd -s {{ server_username }}'
- require:
- cmd: mgradm_install
{% if grains['osfullname'] != 'SLE Micro' %}
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
- pkg: uyuni-tools
{% endif %}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion salt/server_containerized/install_common.sls
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{%- set mirror_hostname = grains.get('server_mounted_mirror') if grains.get('server_mounted_mirror') else grains.get('mirror') %}

{% if grains['osfullname'] != 'SLE Micro' %}
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
uyuni-tools:
pkg.installed:
- pkgs:
Expand Down
2 changes: 2 additions & 0 deletions salt/server_containerized/install_k3s.sls
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include:
- server_containerized.install_common

{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
k3s_install:
cmd.run:
- name: curl -sfL https://get.k3s.io | sh -
Expand All @@ -12,6 +13,7 @@ helm_install:
pkg.installed:
- refresh: True
- name: helm
{% endif %}

chart_values_file:
file.managed:
Expand Down
2 changes: 1 addition & 1 deletion salt/server_containerized/install_mgradm.sls
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mgradm_install:
- unless: helm --kubeconfig /etc/rancher/k3s/k3s.yaml list | grep uyuni
{%- endif %}
- require:
{% if grains['osfullname'] != 'SLE Micro' %}
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
- pkg: uyuni-tools
{% endif %}
- sls: server_containerized.install_common
Expand Down
2 changes: 1 addition & 1 deletion salt/server_containerized/install_podman.sls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include:
- server_containerized.install_common

{% if grains['osfullname'] != 'SLE Micro' %}
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
podman_packages:
pkg.installed:
- pkgs:
Expand Down
47 changes: 38 additions & 9 deletions salt/server_containerized/testsuite.sls
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include:
minima_download:
cmd.run:
- name: mgrctl exec 'curl --output-dir /root -OL https://github.com/uyuni-project/minima/releases/download/v0.4/minima-linux-amd64.tar.gz'
{% if grains['osfullname'] != 'SLE Micro' %}
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
- require:
- pkg: uyuni-tools
{% endif %}
Expand Down Expand Up @@ -52,7 +52,7 @@ test_repo_debian_updates:
- unless: mgrctl exec "ls -d /srv/www/htdocs/pub/TestRepoDebUpdates"
- require:
- cmd: test_repo_debian_updates_script_copy
{% if grains['osfullname'] != 'SLE Micro' %}
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
- pkg: uyuni-tools
{% endif %}
- cmd: testsuite_packages
Expand All @@ -63,7 +63,7 @@ cobbler_configuration:
- name: "mgrctl exec 'sed -i \"s/redhat_management_permissive: false/redhat_management_permissive: true/\" /etc/cobbler/settings.yaml'"
- require:
- sls: server_containerized.install_{{ grains.get('container_runtime') | default('podman', true) }}
{% if grains['osfullname'] != 'SLE Micro' %}
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
- pkg: uyuni-tools
{% endif %}

Expand Down Expand Up @@ -110,11 +110,40 @@ repo_key_import:
- cmd: galaxy_key_copy
{% endif %}

testing_overlay_devel_repo:
cmd.run:
{%- if grains.get('product_version') | default('', true) in ['uyuni-master', 'uyuni-pr', 'uyuni-released'] %}
- name: 'mgrctl exec "zypper -n ar -f -p 96 http://{{ grains.get("mirror") | default("downloadcontent.opensuse.org", true) }}/repositories/systemsmanagement:/Uyuni:/Master/images/repo/Testing-Overlay-POOL-x86_64-Media1/ testing_overlay_devel_repo"'
{%- else %}
- name: 'mgrctl exec "zypper -n ar -f -p 96 http://{{ grains.get("mirror") | default("download.suse.de", true) }}//ibs/Devel:/Galaxy:/Manager:/Head/images/repo/SLE-Module-SUSE-Manager-Testing-Overlay-4.3-POOL-x86_64-Media1/ testing_overlay_devel_repo"'
{%- endif %}
- unless: mgrctl exec "zypper lr" | grep testing_overlay_devel_repo
- require:
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
- pkg: uyuni-tools
{% endif %}
- cmd: repo_key_import

# Allowing downgrade of salt-ssh as it has sometimes a slightly older version than what is in the image
{% if 'build_image' not in grains.get('product_version') | default('', true) %}
saltssh_package:
cmd.run:
- name: mgrctl exec "zypper -n in --allow-downgrade salt-ssh"
- require:
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
- pkg: uyuni-tools
{% endif %}
- cmd: testing_overlay_devel_repo
{% endif %}

testsuite_packages:
cmd.run:
- name: mgrctl exec "zypper -n in iputils expect wget OpenIPMI"
{% if grains['osfullname'] != 'SLE Micro' %}
- require:
{% if 'build_image' not in grains.get('product_version') | default('', true) %}
- cmd: saltssh_package
{% endif %}
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
- pkg: uyuni-tools
{% endif %}

Expand All @@ -130,7 +159,7 @@ create_pillar_top_sls_to_assign_salt_bundle_config:
cmd.run:
- name: mgrctl exec 'echo -e "base:\n '"'"'*'"'"':\n - salt_bundle_config" >/srv/pillar/top.sls'
- require:
{% if grains['osfullname'] != 'SLE Micro' %}
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
- pkg: uyuni-tools
{% endif %}
- sls: server_containerized.install_{{ grains.get('container_runtime') | default('podman', true) }}
Expand All @@ -146,7 +175,7 @@ enable_salt_content_staging_window:
cmd.run:
- name: mgrctl exec 'sed '"'"'/java.salt_content_staging_window =/{h;s/= .*/= 0.033/};${x;/^$/{s//java.salt_content_staging_window = 0.033/;H};x}'"'"' -i /etc/rhn/rhn.conf'
- require:
{% if grains['osfullname'] != 'SLE Micro' %}
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
- pkg: uyuni-tools
{% endif %}
- sls: server_containerized.install_{{ grains.get('container_runtime') | default('podman', true) }}
Expand All @@ -155,7 +184,7 @@ enable_salt_content_staging_advance:
cmd.run:
- name: mgrctl exec 'sed '"'"'/java.salt_content_staging_advance =/{h;s/= .*/= 0.05/};${x;/^$/{s//java.salt_content_staging_advance = 0.05/;H};x}'"'"' -i /etc/rhn/rhn.conf'
- require:
{% if grains['osfullname'] != 'SLE Micro' %}
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
- pkg: uyuni-tools
{% endif %}
- sls: server_containerized.install_{{ grains.get('container_runtime') | default('podman', true) }}
Expand All @@ -164,7 +193,7 @@ enable_kiwi_os_image_building:
cmd.run:
- name: mgrctl exec 'sed '"'"'/java.kiwi_os_image_building_enabled =/{h;s/= .*/= true/};${x;/^$/{s//java.kiwi_os_image_building_enabled = true/;H};x}'"'"' -i /etc/rhn/rhn.conf'
- require:
{% if grains['osfullname'] != 'SLE Micro' %}
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
- pkg: uyuni-tools
{% endif %}
- sls: server_containerized.install_{{ grains.get('container_runtime') | default('podman', true) }}
Expand All @@ -187,7 +216,7 @@ dump_salt_event_log:
- name: mgrctl cp /root/salt-events.service server:/usr/lib/systemd/system/salt-events.service
- require:
- file: salt_event_service_file
{% if grains['osfullname'] != 'SLE Micro' %}
{% if grains['osfullname'] not in ['SLE Micro', 'openSUSE Leap Micro'] %}
- pkg: uyuni-tools
{% endif %}
Expand Down

0 comments on commit 2a5e15f

Please sign in to comment.