Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osbuild: support building kubevirt disks #4034

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/cmd-osbuild
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ declare -A SUPPORTED_PLATFORMS=(
['hetzner']='raw'
['hyperv']='vhdx'
['ibmcloud']='qcow2'
['kubevirt']='ociarchive'
['metal4k']='raw'
['metal']='raw'
['nutanix']='qcow2'
Expand Down Expand Up @@ -222,6 +223,7 @@ generate_runvm_osbuild_config() {
# Generate the JSON describing the disk we want to build
yaml2json /dev/stdin "${runvm_osbuild_config_json}" <<EOF
artifact-name-prefix: "${name}-${build}"
build-version: "${build}"
container-imgref: "${container_imgref}"
deploy-via-container: "${deploy_via_container}"
osname: "${name}"
Expand Down Expand Up @@ -255,6 +257,21 @@ main() {
"cmd-buildextend-qemu-secex") platforms=(qemu-secex);;
"cmd-buildextend-secex") platforms=(qemu-secex);;
"cmd-buildextend-live") platforms=(live);;
"cmd-buildextend-aliyun") platforms=(aliyun);;
"cmd-buildextend-applehv") platforms=(applehv);;
"cmd-buildextend-aws") platforms=(aws);;
"cmd-buildextend-azure") platforms=(azure);;
"cmd-buildextend-azurestack") platforms=(azurestack);;
"cmd-buildextend-digitalocean") platforms=(digitalocean);;
"cmd-buildextend-exoscale") platforms=(exoscale);;
"cmd-buildextend-gcp") platforms=(gcp);;
"cmd-buildextend-hetzner") platforms=(hetzner);;
"cmd-buildextend-hyperv") platforms=(hyperv);;
"cmd-buildextend-ibmcloud") platforms=(ibmcloud);;
"cmd-buildextend-kubevirt") platforms=(kubevirt);;
"cmd-buildextend-nutanix") platforms=(nutanix);;
"cmd-buildextend-openstack") platforms=(openstack);;
"cmd-buildextend-vultr") platforms=(vultr);;
*) fatal "called as unexpected name $0";;
esac

Expand Down Expand Up @@ -395,7 +412,7 @@ main() {

# Perform postprocessing
case "$platform" in
gcp|nutanix)
gcp|kubevirt|nutanix)
# Update the meta.json and builddir with the generated artifact.
# Skip Compression on these platforms as they are either already
# compressed or the artifact itself has internal compression enabled.
Expand Down
2 changes: 2 additions & 0 deletions src/osbuild-manifests/coreos.osbuild.x86_64.mpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ pipelines:
path: platform.hyperv.ipp.yaml
- mpp-import-pipelines:
path: platform.ibmcloud.ipp.yaml
- mpp-import-pipelines:
path: platform.kubevirt.ipp.yaml
- mpp-import-pipelines:
path: platform.openstack.ipp.yaml
- mpp-import-pipelines:
Expand Down
107 changes: 107 additions & 0 deletions src/osbuild-manifests/platform.kubevirt.ipp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# This file defines the artifact to be used for the kubevirt platform.
version: '2'
mpp-vars:
build_version: $build_version
pipelines:
- name: raw-kubevirt-image
build:
mpp-format-string: '{buildroot}'
stages:
- type: org.osbuild.copy
inputs:
tree:
type: org.osbuild.tree
origin: org.osbuild.pipeline
references:
- name:raw-image
options:
paths:
- from: input://tree/disk.img
to: tree:///disk.img
# Increase the size to the cloud image size
- type: org.osbuild.truncate
options:
filename: disk.img
size:
mpp-format-string: "{cloud_image_size_mb * 1024 * 1024}"
- type: org.osbuild.coreos.platform
options:
platform: kubevirt
devices:
disk:
type: org.osbuild.loopback
options:
filename: disk.img
partscan: true
mounts:
- name: root
type: org.osbuild.xfs
source: disk
partition:
mpp-format-int: '{image.layout[''root''].partnum}'
target: /
- name: ostree.deployment
type: org.osbuild.ostree.deployment
options:
source: mount
deployment:
default: true
- name: boot
type: org.osbuild.ext4
source: disk
partition:
mpp-format-int: '{image.layout[''boot''].partnum}'
target: /boot
- name: qemu-kubevirt-image
build:
mpp-format-string: '{host_as_buildroot}'
stages:
# Kubevirt looks for the disk/qcow2 file under the /disk directory.
- type: org.osbuild.mkdir
options:
paths:
- path: /disk
mode: 493
- type: org.osbuild.qemu
inputs:
image:
type: org.osbuild.files
origin: org.osbuild.pipeline
references:
name:raw-kubevirt-image:
file: disk.img
options:
filename:
mpp-format-string: '/disk/{artifact_name_prefix}-kubevirt.{arch}.qcow2'
format:
type: qcow2
compression: false
compat: '1.1'
- name: kubevirt
build:
mpp-format-string: '{buildroot}'
stages:
- type: org.osbuild.oci-archive
inputs:
base:
type: org.osbuild.tree
origin: org.osbuild.pipeline
references:
- name:qemu-kubevirt-image
options:
# For the architecture for containers/registries we have
# to map x86_64->amd64 and aarch64->arm64 for the image build.
architecture:
mpp-if: arch == 'x86_64'
then: amd64
else:
mpp-if: arch == 'aarch64'
then: arm64
else:
mpp-format-string: '{arch}'
filename:
mpp-format-string: '{artifact_name_prefix}-kubevirt.{arch}.ociarchive'
config:
Labels:
version:
mpp-format-string: '{build_version}'
2 changes: 2 additions & 0 deletions src/runvm-osbuild
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ do
done

artifact_name_prefix=$(getconfig_def "artifact-name-prefix" "custom-coreos")
build_version=$(getconfig_def "build-version" "0")
ostree_container=$(getconfig "ostree-container")
osname=$(getconfig "osname")
deploy_via_container=$(getconfig_def "deploy-via-container" "")
Expand Down Expand Up @@ -109,6 +110,7 @@ podman images > /dev/null
set -x; osbuild-mpp \
-D arch=\""$(arch)"\" \
-D artifact_name_prefix=\""${artifact_name_prefix}"\" \
-D build_version=\""${build_version}"\" \
-D ostree_ref=\""${ostree_ref}"\" \
-D ostree_repo=\""${ostree_repo}"\" \
-D ociarchive=\""${ostree_container}"\" \
Expand Down
Loading