Compare commits

...
Sign in to create a new pull request.

10 commits

Author SHA1 Message Date
Eduardo Lima (Etrunko)
b875a3c620 kata-containers-2.1.0-2
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2021-06-04 19:40:10 -03:00
Fabiano Fidêncio
07917ee98a qemu: Update QEMU binary & its location
Let's update the QEMU binary used for Fedora & others and, consequently,
also update their location.

For Fedora we rely on the qemu-system-$arch rather than on qemu-kvm, and
the correct binary will be installed by the qemu-kvm-core package.

For others, we depend on the qemu-kiwi binary.

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
2021-06-04 19:34:38 -03:00
Fabiano Fidêncio
a3cb1c49f3 Add the CRI-O drop-in file to the package
Let's make kata-containers work out-of-the-box with CRI-O, by
adding the drop-in configuration file as part of our package.

Resolves: #1967594

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
2021-06-04 19:34:35 -03:00
Eduardo Lima (Etrunko)
edf25dd4b3 kata-containers-2.1.0 2021-05-27 11:20:29 -03:00
Fabiano Fidêncio
e6a15d5abd Temporarily enable all the annotations
This should is done, at least for now, in order to figure out which are
the annotations we'll actually want to have enabled.  We should **not**
ship with **all** the annotations enabled, but rather with the ones that
are interesting for our use cases.

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
2021-05-27 11:04:56 -03:00
Fabiano Fidêncio
cf2f880959 Call systemd_post on all OSes
Differently than %post actions, %systemd_post does take effect on
rpm-ostree based distros (such as FCOS and RHCOS), and is actually
required on RHCOS in order to have kata-osbuilder-generate.service
enabled, as there the service is part of the their presets.

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
2021-05-27 11:04:38 -03:00
Fabiano Fidêncio
d09402bd8e kata-osbuilder-generate: Mark it as a kubelet dependency
This is more accurate than having it as a dependency of the multi-user
target.

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
2021-05-27 11:02:30 -03:00
Eduardo Lima (Etrunko)
5839375e0d kata-containers-2.0.3 2021-04-09 17:09:42 -03:00
Eduardo Lima (Etrunko)
236eb0fec3 kata-containers-2.0.2 2021-04-06 11:17:30 -03:00
Eduardo Lima (Etrunko)
b45f16d42f kata-containers-2.0.1 2021-03-08 12:14:42 -03:00
11 changed files with 1798108 additions and 0 deletions

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
/kata-containers-2.0.0.tar.gz
/kata-containers-2.0.1.tar.gz
/kata-containers-2.0.2.tar.gz
/kata-containers-2.0.3.tar.gz
/kata-containers-2.1.0.tar.gz

1797288
0001-Add-vendor-code.patch Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,33 @@
From 3a789e01e42537f98b6f73862819c4ecf20ab0e4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
Date: Mon, 30 Nov 2020 16:04:11 +0100
Subject: [PATCH] osbuilder: Adjust agent_version for our builds
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
As we move things around when installing osbuilder, we need to adapt
where we get the agent_version from.
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
---
tools/osbuilder/scripts/lib.sh | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tools/osbuilder/scripts/lib.sh b/tools/osbuilder/scripts/lib.sh
index e7a39d8..f0a41b6 100644
--- a/tools/osbuilder/scripts/lib.sh
+++ b/tools/osbuilder/scripts/lib.sh
@@ -195,8 +195,7 @@ create_summary_file()
if [ "${RUST_AGENT}" == "no" ]; then
agent_version=$("$agent" --version|awk '{print $NF}')
else
- local -r agentdir="${script_dir}/../../../"
- agent_version=$(cat ${agentdir}/VERSION)
+ agent_version=$(cat "${script_dir}/../../VERSION")
fi
--
2.28.0

View file

@ -0,0 +1,25 @@
From 1c65024709d7c28bf78b42c59a135df17513d78d Mon Sep 17 00:00:00 2001
From: Christophe de Dinechin <dinechin@redhat.com>
Date: Thu, 12 Sep 2019 12:57:39 +0200
Subject: [PATCH] Remove shebang in non-executable completion script
Raised during package review [1] by rpmlint
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1590425#c8
Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
---
src/runtime/data/completions/bash/kata-runtime | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/runtime/data/completions/bash/kata-runtime b/src/runtime/data/completions/bash/kata-runtime
index c293483..58ab978 100644
--- a/src/runtime/data/completions/bash/kata-runtime
+++ b/src/runtime/data/completions/bash/kata-runtime
@@ -1,4 +1,3 @@
-#!/bin/bash
#
# Copyright (c) 2018 Intel Corporation
#
--
2.21.0

27
15-dracut-fedora.conf Normal file
View file

@ -0,0 +1,27 @@
# Custom Fedora dracut config for kata initrd/rootfs generation
# Fedora: kernel drivers we want in the initrd.
drivers+=" "
# virtio vsock
drivers+="vmw_vsock_virtio_transport "
# virtio net
drivers+="virtio_net "
# virtio fs
drivers+="virtiofs "
# virtio block
drivers+="virtio_blk "
# virtio scsi
drivers+="virtio_scsi "
# virtio serial. Could be dropped eventually, vsock covers us
drivers+="virtio_console "
# virtio 9p. Could be dropped eventually, virtio-fs covers us
drivers+="9p 9pnet_virtio "
# vfio
drivers+="vfio-pci vfio vfio_iommu_type1 irqbypass vfio_virqfd"
# Fedora: extra dracut modules
dracutmodules+=" "
# These aid debugging
dracutmodules+="bash busybox rescue "

25
15-dracut-rhel.conf Normal file
View file

@ -0,0 +1,25 @@
# Custom RHEL dracut config for kata initrd/rootfs generation
# Fedora: kernel drivers we want in the initrd.
drivers+=" "
# virtio vsock
drivers+="vmw_vsock_virtio_transport "
# virtio net
drivers+="virtio_net "
# virtio fs
drivers+="virtiofs "
# virtio block
drivers+="virtio_blk "
# virtio scsi
drivers+="virtio_scsi "
# virtio serial. Could be dropped eventually, vsock covers us
drivers+="virtio_console "
# vfio
drivers+="vfio-pci vfio vfio_iommu_type1 irqbypass vfio_virqfd"
# Fedora: extra dracut modules
dracutmodules+=" "
# These aid debugging
dracutmodules+="bash rescue "

5
50-kata Normal file
View file

@ -0,0 +1,5 @@
[crio.runtime.runtimes.kata]
runtime_path = "/usr/bin/containerd-shim-kata-v2"
runtime_type = "vm"
runtime_root = "/run/vc"
privileged_without_host_devices = true

406
kata-containers.spec Normal file
View file

@ -0,0 +1,406 @@
# go-rpm-macros are not available on RHEL.
%if 0%{?fedora}
%global have_go_rpm_macros 1
%else
%global have_go_rpm_macros 0
%endif
%global with_debug 0
# Shamelessly copied from CRI-O spec file.
%if 0%{?with_debug}
%global _find_debuginfo_dwz_opts %{nil}
%global _dwz_low_mem_die_limit 0
%else
%global debug_package %{nil}
%endif
# https://github.com/rust-lang/rust/issues/47714
%undefine _strict_symbol_defs_build
# We want verbose builds
%global _configure_disable_silent_rules 1
# Use bundled deps as we don't ship the exact right versions for all the
# required rust libraries
%global bundled_rust_deps 1
# Release candidate version tracking
# global rcver rc0
%if 0%{?rcver:1}
%global rcrel .%{rcver}
%global rcstr -%{rcver}
%endif
# htps://github.com/kata-containers/kata-containers
Version: 2.1.0
%global tag %{version}%{?rcstr}
%global domain github.com
%global org kata-containers
%global repo kata-containers
%global download %{domain}/%{org}/%{repo}
%global importname %{download}
%global common_description %{expand:
Kata Containers version 2.x repository. Kata Containers is an open source
project and community working to build a standard implementation of lightweight
Virtual Machines (VMs) that feel and perform like containers, but provide the
workload isolation and security advantages of VMs. https://katacontainers.io/.}
%global golicenses LICENSE \\\
src/agent/LICENSE
%global godocs README.md \\\
CODE_OF_CONDUCT.md \\\
CONTRIBUTING.md\\\
src/agent/README.md
Name: %{repo}
Release: 2%{?rcrel}%{?dist}
Summary: Kata Containers version 2.x repository
License: ASL 2.0
Url: https://%{download}
Source0: https://%{download}/archive/%{version}%{?rcstr}/%{repo}-%{version}%{?rcstr}.tar.gz
Source1: kata-osbuilder.sh
Source2: kata-osbuilder-generate.service
%if 0%{?fedora}
Source3: 15-dracut-fedora.conf
%else
Source3: 15-dracut-rhel.conf
%endif
Source4: 50-kata
Patch0001: 0001-Add-vendor-code.patch
# Keep this patch downstream as it'd be hard to justify such change upstream
Patch0999: 0999-osbuilder-Adjust-agent_version-for-our-builds.patch
Patch1000: 1000-Remove-shebang-in-non-executable-completion-script.patch
%if 0%{?have_go_rpm_macros}
BuildRequires: go-rpm-macros
%else
BuildRequires: compiler(go-compiler)
BuildRequires: golang
%endif
BuildRequires: git-core
BuildRequires: libselinux-devel
BuildRequires: make
BuildRequires: systemd
BuildRequires: gcc
BuildRequires: protobuf-compiler
%{?systemd_requires}
# %%check requirements
BuildRequires: dracut
BuildRequires: kernel
%if 0%{?fedora}
BuildRequires: busybox
%endif
%if 0%{?bundled_rust_deps}
BuildRequires: cargo
BuildRequires: rust
%else
# Generated using rust2rpm
# [dependencies]
BuildRequires: rust-packaging
BuildRequires: (crate(anyhow/default) >= 1.0.32 with crate(anyhow/default) < 2.0.0)
BuildRequires: (crate(lazy_static/default) >= 1.3.0 with crate(lazy_static/default) < 2.0.0)
BuildRequires: (crate(libc/default) >= 0.2.58 with crate(libc/default) < 0.3.0)
BuildRequires: (crate(log/default) >= 0.4.11 with crate(log/default) < 0.5.0)
BuildRequires: (crate(nix/default) >= 0.17.0 with crate(nix/default) < 0.18.0)
BuildRequires: (crate(prctl/default) >= 1.0.0 with crate(prctl/default) < 2.0.0)
BuildRequires: (crate(procfs/default) >= 0.7.9 with crate(procfs/default) < 0.8.0)
BuildRequires: (crate(prometheus/default) >= 0.9.0 with crate(prometheus/default) < 0.10.0)
BuildRequires: (crate(prometheus/process) >= 0.9.0 with crate(prometheus/process) < 0.10.0)
BuildRequires: (crate(regex/default) >= 1.0.0 with crate(regex/default) < 2.0.0)
BuildRequires: (crate(scan_fmt/default) >= 0.2.3 with crate(scan_fmt/default) < 0.3.0)
BuildRequires: (crate(scopeguard/default) >= 1.0.0 with crate(scopeguard/default) < 2.0.0)
BuildRequires: (crate(serde_json/default) >= 1.0.39 with crate(serde_json/default) < 2.0.0)
BuildRequires: (crate(signal-hook/default) >= 0.1.9 with crate(signal-hook/default) < 0.2.0)
BuildRequires: (crate(slog-scope/default) >= 4.1.2 with crate(slog-scope/default) < 5.0.0)
BuildRequires: (crate(slog-stdlog/default) >= 4.0.0 with crate(slog-stdlog/default) < 5.0.0)
BuildRequires: (crate(slog/default) >= 2.5.2 with crate(slog/default) < 3.0.0)
BuildRequires: (crate(slog/dynamic-keys) >= 2.5.2 with crate(slog/dynamic-keys) < 3.0.0)
BuildRequires: (crate(slog/max_level_trace) >= 2.5.2 with crate(slog/max_level_trace) < 3.0.0)
BuildRequires: (crate(slog/release_max_level_info) >= 2.5.2 with crate(slog/release_max_level_info) < 3.0.0)
BuildRequires: (crate(tempfile/default) >= 3.1.0 with crate(tempfile/default) < 4.0.0)
BuildRequires: crate(cgroups/default) >= 0.0.0
BuildRequires: crate(logging/default) >= 0.0.0
BuildRequires: crate(netlink/default) >= 0.0.0
BuildRequires: crate(netlink/with-agent-handler) >= 0.0.0
BuildRequires: crate(netlink/with-log) >= 0.0.0
BuildRequires: crate(oci/default) >= 0.0.0
BuildRequires: crate(protobuf/default) = 2.14.0
BuildRequires: crate(protocols/default) >= 0.0.0
BuildRequires: crate(rustjail/default) >= 0.0.0
BuildRequires: crate(ttrpc/default) >= 0.0.0
%endif
%if 0%{?fedora}
Requires: busybox
%endif
Requires: dracut
Requires: kernel
Requires: qemu-kvm-core >= 4.2.0-4
Conflicts: kata-agent
Conflicts: kata-ksm-throttler
Conflicts: kata-osbuilder
Conflicts: kata-proxy
Conflicts: kata-runtime
Conflicts: kata-shim
# The following architectures lack the required qemu support
# s390 fail to build: https://github.com/kata-containers/kata-containers/issues/1204
ExcludeArch: %{arm} %{ix86} s390 s390x
%description
%{common_description}
%gopkg
# Common variables to pass to 'make'
# The machine type uses a modern default
# The kernel parameters workaround an issue with cgroupsv2 after kernel 5.3
# To-do: add BUILDFLAGS=gobuildflags when the macro becomes available
%if 0%{?fedora}
%global qemu qemu-system-%{_arch}
%global qemupath %{_bindir}/%{qemu}
%else
%global qemu qemu-kiwi
%global qemupath %{_libexecdir}/%{qemu}
%endif
# The machine type to be used is architecture specific:
# aarch64: virt
# ppc64le: pseries
# s390x: s390-ccw-virtio
# x86_64: q35
%ifarch aarch64
%global machinetype "virt"
%endif
%ifarch ppc64le
%global machinetype "pseries"
%endif
%ifarch s390x
%global machinetype "s390-ccw-virtio"
%endif
%ifarch x86_64
%global machinetype "q35"
%endif
%global katadatadir %{_datadir}/kata-containers
%global katadefaults %{katadatadir}/defaults
%global katacache %{_localstatedir}/cache
%global katalibexecdir %{_libexecdir}/kata-containers
%global katalocalstatecachedir %{katacache}/kata-containers
%global kataagentdir %{katalibexecdir}/agent
%global kataosbuilderdir %{katalibexecdir}/osbuilder
%global runtime_make_vars QEMUPATH=%{qemupath} \\\
KERNELTYPE="compressed" \\\
DEFSHAREDFS="virtio-fs" \\\
DEFVIRTIOFSDAEMON=%{_libexecdir}/"virtiofsd" \\\
DEFVIRTIOFSCACHESIZE=0 \\\
DEFSANDBOXCGROUPONLY=true \\\
SKIP_GO_VERSION_CHECK=y \\\
MACHINETYPE=%{machinetype} \\\
SCRIPTS_DIR=%{_bindir} \\\
DESTDIR=%{buildroot} \\\
PREFIX=/usr \\\
DEFAULTSDIR=%{katadefaults} \\\
CONFDIR=%{katadefaults} \\\
FEATURE_SELINUX="yes" \\\
DEFENABLEANNOTATIONS=['\\\".*\\\"']
%global agent_make_vars LIBC=gnu \\\
DESTDIR=%{buildroot}%{kataagentdir}
%prep
%autosetup -S git -p1 -n %{repo}-%{version}%{?rcstr}
# Not using gobuild here in order to stick to how upstream builds
# (This builds multiple binaries)
%build
export PATH=$PATH:"$(pwd)/go/bin"
export GOPATH="$(pwd)/go"
mkdir -p go/src/%{domain}/%{org}
ln -s $(pwd)/../%{repo}-%{version}%{?rcstr} go/src/%{importname}
cd go/src/%{importname}
pushd src/runtime
%make_build %{runtime_make_vars}
popd
pushd src/agent
%make_build %{agent_make_vars}
touch kata-agent
popd
pushd tools/osbuilder
# Manually build nsdax tool
gcc %{build_cflags} image-builder/nsdax.gpl.c -o nsdax
popd
# Not using gopkginstall here in order to stick to how upstream builds
%install
export GOPATH=$(pwd)/go
export PATH=$PATH:$GOPATH/bin
cd go/src/%{importname}
install -m 0644 -D -t %{buildroot}%{katalibexecdir} VERSION
pushd src/runtime
%make_install %{runtime_make_vars}
popd
pushd src/agent
%make_install %{agent_make_vars}
popd
pushd tools/osbuilder
rm .gitignore
rm rootfs-builder/.gitignore
mkdir -p %{buildroot}%{katalocalstatecachedir}
install -m 0644 -D -t %{buildroot}%{_unitdir} %{SOURCE2}
install -m 0755 -D -t %{buildroot}%{kataosbuilderdir} nsdax
install -m 0644 -D -t %{buildroot}%{kataosbuilderdir} %{SOURCE1}
cp -aR rootfs-builder %{buildroot}%{kataosbuilderdir}
cp -aR image-builder %{buildroot}%{kataosbuilderdir}
cp -aR initrd-builder %{buildroot}%{kataosbuilderdir}
cp -aR scripts %{buildroot}%{kataosbuilderdir}
cp -aR dracut %{buildroot}%{kataosbuilderdir}
rm -f %{buildroot}%{kataosbuilderdir}/image-builder/nsdax.gpl.c
install -m 0644 -D -t %{buildroot}%{kataosbuilderdir}/dracut/dracut.conf.d/ %{SOURCE3}
chmod +x %{buildroot}%{kataosbuilderdir}/scripts/lib.sh
chmod +x %{buildroot}%{kataosbuilderdir}/kata-osbuilder.sh
popd
# Install the CRI-O config drop-in file
install -m 0644 -D -t %{buildroot}%{_sysconfdir}/crio/crio.conf.d %{SOURCE4}
# Disable the image= option, so we use initrd= by default
# The kernels kata-osbuilder creates are in /var/cache now, see rhbz#1792216
sed -i -e 's|^kernel = "%{_datadir}|kernel = "%{katacache}|' \
-e 's|^image = "%{_datadir}/kata-containers/kata-containers.img"|initrd = "%{katacache}/kata-containers/kata-containers-initrd.img"|' \
%{buildroot}%{_datadir}/kata-containers/defaults/configuration.toml
# Enable vsock as transport instead of virtio-serial
sed -i -e 's/^#use_vsock =/use_vsock =/' %{buildroot}%{_datadir}/kata-containers/defaults/configuration.toml
# Remove non-tested / non-supported configuration files
rm %{buildroot}%{_datadir}/kata-containers/defaults/configuration-*.toml
# We could be run in a mock chroot, where uname will report
# different kernel than what we have installed in the chroot.
# So we need to determine a valid kernel version to test against.
for kernelpath in /lib/modules/*/vmlinu*; do
KVERSION="$(echo $kernelpath | cut -d "/" -f 4)"
break
done
TEST_MODE=1 %{buildroot}%{kataosbuilderdir}/kata-osbuilder.sh \
-o %{buildroot}%{kataosbuilderdir} \
-k "$KVERSION" \
-a %{buildroot}
%preun
%systemd_preun kata-osbuilder-generate.service
%postun
%systemd_postun kata-osbuilder-generate.service
%post
%systemd_post kata-osbuilder-generate.service
# Skip running this on Fedora CoreOS / Red Hat CoreOS
if test -w %{katalocalstatecachedir}; then
TMPOUT="$(mktemp -t kata-rpm-post-XXXXXX.log)"
echo "Creating kata appliance initrd..."
%{kataosbuilderdir}/kata-osbuilder.sh > ${TMPOUT} 2>&1
if test "$?" != "0" ; then
echo "Building failed. Here is the log details:"
cat ${TMPOUT}
exit 1
fi
fi
%files
# runtime
%{_bindir}/kata-runtime
%{_bindir}/kata-monitor
%{_bindir}/containerd-shim-kata-v2
%{_bindir}/kata-collect-data.sh
%dir %{katalibexecdir}
%{katalibexecdir}/VERSION
%{katalibexecdir}/kata-netmon
%dir %{katadatadir}
%dir %{katadefaults}
%{katadefaults}/configuration.toml
%{_datadir}/bash-completion/completions/kata-runtime
%license LICENSE
%doc README.md CONTRIBUTING.md
#agent
%dir %{kataagentdir}
%{kataagentdir}/*
#osbuilder
%dir %{kataosbuilderdir}
%dir %{katalocalstatecachedir}
%{kataosbuilderdir}/*
%{_unitdir}/kata-osbuilder-generate.service
# CRI-O drop-in file
%{_sysconfdir}/crio/crio.conf.d/50-kata
# Remove some scripts we don't use
%exclude %{kataosbuilderdir}/rootfs-builder/alpine
%exclude %{kataosbuilderdir}/rootfs-builder/centos
%exclude %{kataosbuilderdir}/rootfs-builder/clearlinux
%exclude %{kataosbuilderdir}/rootfs-builder/debian
%exclude %{kataosbuilderdir}/rootfs-builder/fedora
%exclude %{kataosbuilderdir}/rootfs-builder/template
%exclude %{kataosbuilderdir}/rootfs-builder/suse
%exclude %{kataosbuilderdir}/rootfs-builder/ubuntu
%changelog
* Thu May 27 2021 Eduardo Lima (Etrunko) <etrunko@redhat.com> - 2.1.0-2
- Add the CRI-O drop-in file to the package
Resolves: rhbz#1967594
- qemu: Update QEMU binary & its location
Resolves: rhbz#1967602
* Thu May 27 2021 Eduardo Lima (Etrunko) <etrunko@redhat.com> - 2.1.0-1
- kata-containers 2.1.0
* Fri Apr 09 2021 Eduardo Lima (Etrunko) <etrunko@redhat.com> - 2.0.3-1
- kata-containers 2.0.3
* Tue Apr 06 2021 Eduardo Lima (Etrunko) <etrunko@redhat.com> - 2.0.2-1
- kata-containers 2.0.2
* Mon Mar 08 2021 Eduardo Lima (Etrunko) <etrunko@redhat.com> - 2.0.1-1
- Kata-containers 2.0.1
* Thu Dec 17 2020 Eduardo Lima (Etrunko) <etrunko@redhat.com> - 2.0.0-1
- Adjust package for Fedora review.
* Thu Nov 26 2020 Fabiano Fidêncio <fabiano@fidencio.org> - 2.0.0-0
- Initial packaging

View file

@ -0,0 +1,10 @@
[Unit]
Description=Generate Kata appliance image for host kernel
[Service]
Type=oneshot
ExecStart=/usr/libexec/kata-containers/osbuilder/kata-osbuilder.sh -c
ExecReload=/usr/libexec/kata-containers/osbuilder/kata-osbuilder.sh
[Install]
WantedBy=kubelet.service

283
kata-osbuilder.sh Executable file
View file

@ -0,0 +1,283 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
[ -n "${DEBUG:-}" ] && set -o xtrace
readonly IMAGE_TOPDIR="/var/cache/kata-containers"
readonly KERNEL_SYMLINK="${IMAGE_TOPDIR}/vmlinuz.container"
readonly SCRIPTNAME="$0"
readonly DRACUT_ROOTFS=`mktemp --directory -t kata-dracut-rootfs-XXXXXX`
readonly DRACUT_IMAGES=`mktemp --directory -t kata-dracut-images-XXXXXX`
trap exit_handler EXIT
readonly GENERATED_IMAGE="${DRACUT_IMAGES}/kata-containers.img"
readonly GENERATED_INITRD="${DRACUT_IMAGES}/kata-containers-initrd.img"
readonly DISTRO=`grep '^ID=' /etc/os-release | awk '{print $2}' FS='='`
KVERSION=`uname -r`
KERNEL_PATH=""
COMMAND=""
OSBUILDER_DIR="/usr/libexec/kata-containers/osbuilder"
GENERATE_IMAGE=""
AGENT_DIR_PREFIX=""
# rpm %check sets this to run the script without overwriting host
# content, and not requiring root
TEST_MODE="${TEST_MODE:-}"
die()
{
error "$*"
exit 1
}
error()
{
echo "ERROR: ${SCRIPTNAME}: $*" >&2
}
info()
{
echo "${SCRIPTNAME}: $*"
}
exit_handler()
{
rm -rf "${DRACUT_ROOTFS}" "${DRACUT_IMAGES}"
}
usage()
{
cat <<EOT
Usage: ${SCRIPTNAME} [options]
This script builds the kata appliance initrd and image and adds
stable symlink paths in ${IMAGE_TOPDIR}
This script is called at kata-osbuilder at RPM install %post time and
via kata-osbuilder-generate.service
Options:
-h Show this help message
-c Check if an initrd is already generated for the current
kernel, and if so, simply exit
-i Also generate media for kata image= option. kata
image= doesn't work out of the box with Fedora/RHEL
distro kernels so media is not generated by default.
-k Manually specify kernel version to use. Default comes
from uname. Default: ${KVERSION}
-o DIRNAME Use the passed directory for osbuilder code. Point
To a git checkout if you want to use upstream osbuilder.
Default: ${OSBUILDER_DIR}
-a DIRNAME Use the passed directory as the agent_dir prefix. It's
mostly useful for pointing to an uninstalled kata-agent.
Default: ${AGENT_DIR_PREFIX}
EOT
exit $1
}
parse_args()
{
while getopts "chik:o:a:" opt
do
case $opt in
c) COMMAND="check" ;;
h) usage 0 ;;
i) GENERATE_IMAGE=1 ;;
o) OSBUILDER_DIR="${OPTARG}" ;;
k) KVERSION="${OPTARG}" ;;
a) AGENT_DIR_PREFIX="${OPTARG}" ;;
*) usage 1 ;;
esac
done
shift $(($OPTIND - 1))
if [ -n "$*" ]; then
error "Unhandled options: '$*'"
usage 1
fi
}
find_host_kernel_path()
{
local modpath="/lib/modules/$KVERSION/"
[ ! -e "$modpath" ] && die "version=$KVERSION path=$modpath does not exist"
local vmname
for vmname in vmlinuz vmlinux; do
local trypath="$modpath/$vmname"
if [ -e "$trypath" ] ; then
KERNEL_PATH="$trypath"
break
fi
done
[ -z "$KERNEL_PATH" ] && die "Didn't find vmlinu* path in $modpath"
if [ "$COMMAND" = "check" ]; then
local linked_kernel=$(readlink -n "${KERNEL_SYMLINK}" || :)
if [ "${KERNEL_PATH}" = "${linked_kernel}" ] ; then
info "symlink=${KERNEL_SYMLINK} already points to host kernel=${KERNEL_PATH}"
info "Nothing to generate. Exiting."
exit 0
fi
fi
}
generate_modules_load_conf()
{
# Write the modules-load file from all driver .ko.* files in the initrd
local loadfile="${DRACUT_ROOTFS}/etc/modules-load.d/kata-modules.conf"
mkdir -p $(dirname $loadfile)
local modpath
for modpath in `find ${DRACUT_ROOTFS} -path \*lib/modules/\*\.ko\*`; do
local name=$(echo $(basename ${modpath}) | cut -d '.' -f 1)
echo "${name}" >> $loadfile
done
}
generate_rootfs()
{
# To generate the rootfs, we build an initrd with dracut, extract
# the initrd content, and then discard the initrd. We then rebuild
# the initrd using the osbuilder native scripts.
#
# This is a bit wasteful, but it's the easiest way to work around
# obuilder script inflexibility for now, which expect that some rootfs.sh
# code is called on a fully populated distro root.
local agent_dir="${AGENT_DIR_PREFIX}/usr/libexec/kata-containers/agent"
if [ -n "${TEST_MODE}" ] ; then
nsdax_bin="${OSBUILDER_DIR}/nsdax"
fi
local agent_source_bin="${agent_dir}/usr/bin/kata-agent"
local osbuilder_version="${DISTRO}-osbuilder-version-unknown"
local dracut_conf_dir="./dracut/dracut.conf.d"
local tmp_initrd=`mktemp --tmpdir=${DRACUT_IMAGES}`
unlink "$tmp_initrd"
# Build the initrd
echo -e "+ Building dracut initrd"
dracut \
--confdir "${dracut_conf_dir}" \
--no-compress \
--conf /dev/null \
${tmp_initrd} ${KVERSION}
# Extract the generated rootfs
echo "+ Extracting dracut initrd rootfs"
cat ${tmp_initrd} | \
cpio --extract --preserve-modification-time --make-directories --directory=${DRACUT_ROOTFS}
# Using the busybox dracut module sets /sbin/init -> busybox
# We don't want that. Reset it to systemd
ln -sf ../lib/systemd/systemd ${DRACUT_ROOTFS}/usr/sbin/init
echo "+ Copying agent directory tree into place"
cp -ar ${agent_dir}/* ${DRACUT_ROOTFS}
# Make kata specific adjustments to our rootfs
echo "Calling osbuilder rootfs.sh on extracted rootfs"
AGENT_SOURCE_BIN="${agent_source_bin}" RUST_AGENT="yes" \
./rootfs-builder/rootfs.sh \
-o ${osbuilder_version} \
-r ${DRACUT_ROOTFS}
# Generate modules-load.d file
generate_modules_load_conf
}
move_images()
{
# Move images into place
local image_osbuilder_dir="${IMAGE_TOPDIR}/osbuilder-images"
local image_dir="${image_osbuilder_dir}/$KVERSION"
local initrd_dest_path="${image_dir}/${DISTRO}-kata-${KVERSION}.initrd"
local image_dest_path="${image_dir}/${DISTRO}-kata-${KVERSION}.img"
local image_dest_link="${IMAGE_TOPDIR}/kata-containers.img"
# This blows away the entire osbuilder-images/ dir, deleting any
# previously cached content
rm -rf "${image_osbuilder_dir}"
mkdir -p "${image_dir}"
ln -sf ${KERNEL_PATH} ${KERNEL_SYMLINK}
mv -Z ${GENERATED_INITRD} ${initrd_dest_path}
ln -sf ${initrd_dest_path} ${IMAGE_TOPDIR}/kata-containers-initrd.img
if [ -n "${GENERATE_IMAGE}" ]; then
mv -Z ${GENERATED_IMAGE} ${image_dest_path}
ln -sf ${image_dest_path} ${image_dest_link}
else
rm -f ${image_dest_link}
fi
}
main()
{
parse_args $*
if [ -z "${TEST_MODE}" ]; then
[ "$(id -u)" -eq 0 ] || die "$0: must be run as root"
fi
find_host_kernel_path
cd "${OSBUILDER_DIR}"
# Generate the rootfs using dracut
generate_rootfs
if [ -n "${TEST_MODE}" ]; then
echo "+ Exiting TEST_MODE successfully"
return
fi
# Build the initrd
echo "+ Calling osbuilder initrd_builder.sh"
./initrd-builder/initrd_builder.sh -o ${GENERATED_INITRD} ${DRACUT_ROOTFS}
if [ -n "${GENERATE_IMAGE}" ]; then
# Build the FS image
local nsdax_bin="/usr/libexec/kata-containers/osbuilder/nsdax"
echo "+ Calling osbuilder image_builder.sh"
NSDAX_BIN="${nsdax_bin}" \
./image-builder/image_builder.sh \
-o ${GENERATED_IMAGE} ${DRACUT_ROOTFS}
fi
move_images
}
main $*

1
sources Normal file
View file

@ -0,0 +1 @@
SHA512 (kata-containers-2.1.0.tar.gz) = ccfc712168738fce1f26b14fbe4a0dcecd9d1f3a0698c06487d98091173951be141c06b4314712ea9b67cda93d2efa8701c3b9afc8770458147defa5adbabf1a