From 59eac1cb418aa6e6d902e492a8cb1b165e9d6c9c Mon Sep 17 00:00:00 2001 From: Andrew Durbin Date: Wed, 15 May 2024 17:22:11 -0600 Subject: [PATCH] Kubevirt: Tag external-boot-image with eve-release At build of pkg/kube: Save pkg/external-boot-image tag to pkg/kube/external-boot-image.tag During runtime of cluster-init.sh: Import and tag external-boot-image to contents of /run/eve-release pillar kubevirt hypervisor will read /run/eve-release to generate the external-boot-image tag to use. Signed-off-by: Andrew Durbin --- Makefile | 4 ++-- pkg/kube/Dockerfile | 1 + pkg/kube/cluster-init.sh | 7 ++++++- pkg/pillar/hypervisor/kubevirt.go | 6 +++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 077f7c3ed4..d38bb6b087 100644 --- a/Makefile +++ b/Makefile @@ -798,8 +798,8 @@ pkg/external-boot-image/build.yml: pkg/external-boot-image/build.yml.in pkg/external-boot-image: pkg/external-boot-image/build.yml pkg/kube: pkg/external-boot-image $(MAKE) eve-external-boot-image - $(MAKE) cache-export IMAGE=$(shell $(LINUXKIT) pkg show-tag pkg/external-boot-image) OUTFILE=pkg/kube/external-boot-image.tar && \ - $(MAKE) eve-kube && rm -f pkg/kube/external-boot-image.tar && rm -f pkg/external-boot-image/build.yml + $(MAKE) cache-export IMAGE=$(shell $(LINUXKIT) pkg show-tag pkg/external-boot-image | tee pkg/kube/external-boot-image.tag) OUTFILE=pkg/kube/external-boot-image.tar && \ + $(MAKE) eve-kube && rm -f pkg/kube/external-boot-image.tar pkg/kube/external-boot-image.tag pkg/external-boot-image/build.yml $(QUIET): $@: Succeeded pkg/pillar: pkg/dnsmasq pkg/gpt-tools pkg/dom0-ztools eve-pillar $(QUIET): $@: Succeeded diff --git a/pkg/kube/Dockerfile b/pkg/kube/Dockerfile index 6df45eec85..1e87311886 100644 --- a/pkg/kube/Dockerfile +++ b/pkg/kube/Dockerfile @@ -37,6 +37,7 @@ COPY multus-daemonset.yaml /etc COPY kubevirt-operator.yaml /etc COPY kubevirt-features.yaml /etc COPY external-boot-image.tar /etc/ +COPY external-boot-image.tag /etc/ # Longhorn config COPY iscsid.conf /etc/iscsi/ diff --git a/pkg/kube/cluster-init.sh b/pkg/kube/cluster-init.sh index 1e07290d1c..5673c4f4c4 100755 --- a/pkg/kube/cluster-init.sh +++ b/pkg/kube/cluster-init.sh @@ -294,7 +294,12 @@ check_start_containerd() { # This is very similar to what we do on kvm based eve to start container as a VM. logmsg "Trying to install new external-boot-image" # This import happens once per reboot - if ctr -a /run/containerd-user/containerd.sock image import /etc/external-boot-image.tar docker.io/lfedge/eve-external-boot-image:latest; then + if ctr -a /run/containerd-user/containerd.sock image import /etc/external-boot-image.tar; then + eve_external_boot_img_tag=$(cat /run/eve-release) + eve_external_boot_img=docker.io/lfedge/eve-external-boot-image:"$eve_external_boot_img_tag" + import_tag=$(cat /etc/external-boot-image.tag) + ctr -a /run/containerd-user/containerd.sock image tag "docker.io/${import_tag}" "$eve_external_boot_img" + logmsg "Successfully installed external-boot-image" rm -f /etc/external-boot-image.tar fi diff --git a/pkg/pillar/hypervisor/kubevirt.go b/pkg/pillar/hypervisor/kubevirt.go index 799526e432..7396c52d59 100644 --- a/pkg/pillar/hypervisor/kubevirt.go +++ b/pkg/pillar/hypervisor/kubevirt.go @@ -296,7 +296,11 @@ func (ctx kubevirtContext) CreateVMIConfig(domainName string, config types.Domai // https://kubevirt.io/user-guide/virtual_machines/boot_from_external_source/ // Since disks are virtio disks we assume /dev/vda is the boot disk kernelArgs := "console=tty0 root=/dev/vda dhcp=1 rootfstype=ext4" - scratchImage := "docker.io/lfedge/eve-external-boot-image:latest" + eveRelease, err := os.ReadFile("/run/eve-release") + if err != nil { + return logError("Failed to fetch eve-release %v", err) + } + scratchImage := "docker.io/lfedge/eve-external-boot-image:" + string(eveRelease) kernelPath := "/kernel" initrdPath := "/runx-initrd"