Merge pull request #8958 from fidencio/topic/kata-manager-nerdctl-support

kata-manager: Add support for nerdctl installation
This commit is contained in:
Fabiano Fidêncio 2024-02-06 21:33:48 +01:00 committed by GitHub
commit 11ba90ebf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,6 +31,11 @@ readonly docker_slug="moby/moby"
readonly docker_project="Docker (moby)" readonly docker_project="Docker (moby)"
readonly docker_releases_url="https://api.github.com/repos/${docker_slug}/releases" readonly docker_releases_url="https://api.github.com/repos/${docker_slug}/releases"
readonly nerdctl_slug="containerd/nerdctl"
readonly nerdctl_project="nerdctl"
readonly nerdctl_releases_url="https://api.github.com/repos/${nerdctl_slug}/releases"
readonly nerdctl_supported_arches="x86_64 aarch64"
# Directory created when unpacking a binary release archive downloaded from # Directory created when unpacking a binary release archive downloaded from
# $kata_releases_url. # $kata_releases_url.
readonly kata_install_dir="${kata_install_dir:-/opt/kata}" readonly kata_install_dir="${kata_install_dir:-/opt/kata}"
@ -182,6 +187,10 @@ github_get_release_file_url()
case "$url" in case "$url" in
*kata*) *kata*)
regex="kata-static-${version}-${arch_regex}.tar.xz" ;; regex="kata-static-${version}-${arch_regex}.tar.xz" ;;
*nerdctl*)
# Keep this *always* before the containerd check, as it comes from
# the very same containerd organisation on GitHub.
regex="nerdctl-full-${version_number}-linux-${arch_regex}.tar.gz" ;;
*containerd*) *containerd*)
regex="containerd-${version_number}-linux-${arch_regex}.tar.gz" ;; regex="containerd-${version_number}-linux-${arch_regex}.tar.gz" ;;
*) die "invalid url: '$url'" ;; *) die "invalid url: '$url'" ;;
@ -261,6 +270,7 @@ Options:
https://containerd.io/releases/#support-horizon https://containerd.io/releases/#support-horizon
-d : Enable debug for all components. -d : Enable debug for all components.
-D : Install Docker server and CLI tooling (takes priority over '-c'). -D : Install Docker server and CLI tooling (takes priority over '-c').
-N : Install nerdctl (takes priority over '-c', only implemented for x86_64 and ARM).
-f : Force installation (use with care). -f : Force installation (use with care).
-h : Show this help statement. -h : Show this help statement.
-k <version> : Specify Kata Containers version. -k <version> : Specify Kata Containers version.
@ -467,15 +477,55 @@ install_containerd()
info "$project installed\n" info "$project installed\n"
} }
install_nerdctl()
{
local project="$nerdctl_project"
info "Downloading $project latest release"
local results
results=$(github_download_package \
"$nerdctl_releases_url" \
"" \
"$project")
[ -z "$results" ] && die "Cannot download $project release file"
local version
version=$(echo "$results"|cut -d: -f1)
local file
file=$(echo "$results"|cut -d: -f2-)
[ -z "$version" ] && die "Cannot determine $project resolved version"
[ -z "$file" ] && die "Cannot determine $project release file"
info "Installing $project release $version from $file"
sudo tar -C /usr/local -xvf "${file}"
for file in \
/usr/local/bin/containerd \
/usr/local/bin/ctr \
/usr/local/bin/nerdctl
do
sudo ln -sf "$file" "${link_dir}"
done
info "$project installed\n"
}
configure_containerd() configure_containerd()
{ {
local enable_debug="${1:-}" local enable_debug="${1:-}"
[ -z "$enable_debug" ] && die "no enable debug value" [ -z "$enable_debug" ] && die "no enable debug value"
local configure_systemd_service="${2:-true}"
local project="$containerd_project" local project="$containerd_project"
info "Configuring $project" info "Configuring $project"
if [ "$configure_systemd_service" = "true" ]
then
local systemd_unit_dir="/etc/systemd/system" local systemd_unit_dir="/etc/systemd/system"
sudo mkdir -p "$systemd_unit_dir" sudo mkdir -p "$systemd_unit_dir"
@ -505,6 +555,7 @@ configure_containerd()
popd >/dev/null popd >/dev/null
fi fi
fi
# Backup the original containerd configuration: # Backup the original containerd configuration:
sudo mkdir -p "$(dirname $containerd_config)" sudo mkdir -p "$(dirname $containerd_config)"
@ -572,6 +623,7 @@ configure_containerd()
fi fi
[ "$modified" = "true" ] && info "Modified containerd config file '$containerd_config'" [ "$modified" = "true" ] && info "Modified containerd config file '$containerd_config'"
sudo systemctl daemon-reload
sudo systemctl enable containerd sudo systemctl enable containerd
sudo systemctl start containerd sudo systemctl start containerd
@ -782,6 +834,25 @@ handle_docker()
docker --version docker --version
} }
handle_nerdctl()
{
{ containerd_installed; ret=$?; } || true
if [ "$ret" -eq 0 ]
then
info "Backing up previous $containerd_project configuration"
[ -e "$containerd_config" ] && sudo mv $containerd_config $containerd_config.system-$(date -Iseconds)
fi
install_nerdctl
configure_containerd "$enable_debug" "false"
sudo systemctl enable --now containerd
containerd --version
nerdctl --version
}
test_installation() test_installation()
{ {
local tool="${1:-}" local tool="${1:-}"
@ -853,9 +924,11 @@ handle_installation()
local kata_version="${7:-}" local kata_version="${7:-}"
local containerd_flavour="${8:-}" local containerd_flavour="${8:-}"
local install_docker="${9:-}" local install_docker="${9:-}"
local install_nerdctl="${10:-}"
[ -z "$install_docker" ] && die "no install docker value" [ -z "$install_docker" ] && die "no install docker value"
[ -z "$install_nerdctl" ] && die "no install nerdctl value"
local kata_tarball="${10:-}" local kata_tarball="${11:-}"
# The tool to be testing the installation with # The tool to be testing the installation with
local tool="ctr" local tool="ctr"
@ -871,6 +944,24 @@ handle_installation()
tool="docker" tool="docker"
fi fi
if [ "$install_nerdctl" = "true" ]
then
local arch=$(uname -m)
if ! grep -q " $arch " <<< " $nerdctl_supported_arches "
then
die "nerdctl deployment only supports $nerdctl_supported_arches"
fi
if [ "$skip_containerd" = "false" ]
then
# The script provided by nerdctl already takes care
# of properly installing containerd
skip_containerd="true"
info "Containerd will be installed during the nerdctl installation ('-c' option ignored)"
fi
tool="nerdctl"
fi
[ "$only_run_test" = "true" ] && test_installation "$tool" && return 0 [ "$only_run_test" = "true" ] && test_installation "$tool" && return 0
setup "$cleanup" "$force" "$skip_containerd" setup "$cleanup" "$force" "$skip_containerd"
@ -883,16 +974,22 @@ handle_installation()
"$force" \ "$force" \
"$enable_debug" "$enable_debug"
[ "$install_docker" = "true" ] && [ "$install_nerdctl" = "true" ] && \
die "Installing docker and nerdctl at the same time is not possible."
[ "$install_docker" = "true" ] && handle_docker [ "$install_docker" = "true" ] && handle_docker
[ "$install_nerdctl" = "true" ] && handle_nerdctl
[ "$disable_test" = "false" ] && test_installation "$tool" [ "$disable_test" = "false" ] && test_installation "$tool"
if [ "$skip_containerd" = "true" ] && [ "$install_docker" = "false" ] if [ "$skip_containerd" = "true" ] && ( [ "$install_docker" = "false" ] || [ "$install_nerdctl" = "false" ] )
then then
info "$kata_project is now installed" info "$kata_project is now installed"
else else
local extra_projects="containerd" local extra_projects="containerd"
[ "$install_docker" = "true" ] && extra_projects+=" and docker" [ "$install_docker" = "true" ] && extra_projects+=" and docker"
[ "$install_nerdctl" = "true" ] && extra_projects+=" and nerdctl"
info "$kata_project and $extra_projects are now installed" info "$kata_project and $extra_projects are now installed"
fi fi
@ -965,6 +1062,7 @@ handle_args()
local only_run_test="false" local only_run_test="false"
local enable_debug="false" local enable_debug="false"
local install_docker="false" local install_docker="false"
local install_nerdctl="false"
local list_versions='false' local list_versions='false'
local opt local opt
@ -973,7 +1071,7 @@ handle_args()
local containerd_flavour="lts" local containerd_flavour="lts"
local kata_tarball="" local kata_tarball=""
while getopts "c:dDfhk:K:lortT" opt "$@" while getopts "c:dDfhk:K:lNortT" opt "$@"
do do
case "$opt" in case "$opt" in
c) containerd_flavour="$OPTARG" ;; c) containerd_flavour="$OPTARG" ;;
@ -984,6 +1082,7 @@ handle_args()
k) kata_version="$OPTARG" ;; k) kata_version="$OPTARG" ;;
K) kata_tarball="$OPTARG" ;; K) kata_tarball="$OPTARG" ;;
l) list_versions='true' ;; l) list_versions='true' ;;
N) install_nerdctl="true" ;;
o) skip_containerd="true" ;; o) skip_containerd="true" ;;
r) cleanup="false" ;; r) cleanup="false" ;;
t) disable_test="true" ;; t) disable_test="true" ;;
@ -1012,6 +1111,7 @@ handle_args()
"$kata_version" \ "$kata_version" \
"$containerd_flavour" \ "$containerd_flavour" \
"$install_docker" \ "$install_docker" \
"$install_nerdctl" \
"$kata_tarball" "$kata_tarball"
} }