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 committed Feb 13, 2024
1 parent 211dc54 commit 0c83113
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 5 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 @@ -3,6 +3,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 @@ -12,6 +13,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 @@ -40,8 +44,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 @@ -65,6 +69,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 @@ -134,7 +160,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/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 ! ['SLE Micro', 'openSUSE Leap Micro'].contains(grains['osfullname']) %}
uyuni-tools:
pkg.installed:
- pkgs:
Expand Down

0 comments on commit 0c83113

Please sign in to comment.