From 0352f1e02964d3b10a1306f4c2e079cb4137d834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Fri, 3 Nov 2023 12:09:45 +0100 Subject: [PATCH 1/3] kata-manager: Allow passing a specific tool to test_installation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Right now we're only testing with `ctr` and there's no change in behaviour with this commit. However, allowing to pass a tool to run the tests with gives us an easier time when expanding kata-manager to support, for instance, docker and nerdctl. Signed-off-by: Fabiano FidĂȘncio --- utils/kata-manager.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/utils/kata-manager.sh b/utils/kata-manager.sh index a41f22e249..4973114951 100755 --- a/utils/kata-manager.sh +++ b/utils/kata-manager.sh @@ -722,19 +722,22 @@ handle_containerd() test_installation() { + local tool="${1:-}" + [ -z "$tool" ] && die "The tool to test $kata_project with was not informed" + info "Testing $kata_project\n" sudo kata-runtime check -v local image="docker.io/library/busybox:latest" - sudo ctr image pull "$image" + sudo $tool image pull "$image" local container_name="test-kata" # Used to prove that the kernel in the container # is different to the host kernel. local container_kernel - container_kernel=$(sudo ctr run \ + container_kernel=$(sudo $tool run \ --runtime "$kata_runtime_type" \ --rm \ "$image" \ @@ -777,7 +780,10 @@ handle_installation() local kata_version="${7:-}" local containerd_flavour="${8:-}" - [ "$only_run_test" = "true" ] && test_installation && return 0 + # The tool to be testing the installation with + local tool="ctr" + + [ "$only_run_test" = "true" ] && test_installation "$tool" && return 0 setup "$cleanup" "$force" "$skip_containerd" @@ -789,7 +795,7 @@ handle_installation() "$force" \ "$enable_debug" - [ "$disable_test" = "false" ] && test_installation + [ "$disable_test" = "false" ] && test_installation "$tool" if [ "$skip_containerd" = "true" ] then From 66d1b2c173a1f2f564cabf2ae64c670b661946d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 2 Nov 2023 14:50:00 +0100 Subject: [PATCH 2/3] kata-manager: Add support for docker installation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for also installing the Docker CLI, giving users the chance to try Kata Containers with docker in the same way we provide users the chance to try Kata Containers with `ctr`. Fixes: #8357 Signed-off-by: Fabiano FidĂȘncio --- utils/kata-manager.sh | 89 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 12 deletions(-) diff --git a/utils/kata-manager.sh b/utils/kata-manager.sh index 4973114951..c9e70c7d7a 100755 --- a/utils/kata-manager.sh +++ b/utils/kata-manager.sh @@ -244,6 +244,7 @@ Options: Find more details on LTS and Active versions of containerd on https://containerd.io/releases/#support-horizon -d : Enable debug for all components. + -D : Install Docker server and CLI tooling (takes priority over '-c'). -f : Force installation (use with care). -h : Show this help statement. -k : Specify Kata Containers version. @@ -720,10 +721,41 @@ handle_containerd() containerd --version } +handle_docker() +{ + { containerd_installed; ret=$?; } || true + if [ "$ret" -eq 0 ] + then + info "Backing up previous $containerd_project configuration" + local cfg="/etc/containerd/config.toml" + + [ -e "$cfg" ] && sudo mv $cfg $cfg.system-$(date -Iseconds) + fi + + containerd_installed + + local filename='get-docker.sh' + + local file + file="$tmpdir/$filename" + + curl -fsSL https://get.docker.com -o "$file" + sudo sh "$file" + + rm -rf "$file" + + sudo systemctl enable --now docker + + configure_containerd "$enable_debug" + + containerd --version + docker --version +} + test_installation() { local tool="${1:-}" - [ -z "$tool" ] && die "The tool to test $kata_project with was not informed" + [ -z "$tool" ] && die "The tool to test $kata_project with was not specified" info "Testing $kata_project\n" @@ -736,13 +768,24 @@ test_installation() # Used to prove that the kernel in the container # is different to the host kernel. - local container_kernel - container_kernel=$(sudo $tool run \ - --runtime "$kata_runtime_type" \ - --rm \ - "$image" \ - "$container_name" \ - uname -r || true) + cmd="sudo $tool run --runtime "$kata_runtime_type" --rm" + case "$tool" in + docker) + # docker takes the container name as `--name + # $container_name`, passed to the run option. + cmd+=" --name $container_name" ;; + esac + cmd+=" $image" + case "$tool" in + ctr) + # ctr takes the container name as a mandatory + # argument after the image name + cmd+=" $container_name" ;; + esac + cmd+=" uname -r" + + info "Running \"$cmd\"" + container_kernel=$(eval "$cmd" || true) [ -z "$container_kernel" ] && die "Failed to test $kata_project" @@ -780,9 +823,24 @@ handle_installation() local kata_version="${7:-}" local containerd_flavour="${8:-}" + local install_docker="${9:-}" + [ -z "$install_docker" ] && die "no install docker value" + # The tool to be testing the installation with local tool="ctr" + if [ "$install_docker" = "true" ] + then + if [ "$skip_containerd" = "false" ] + then + # The script provided by docker already takes care + # of properly installing containerd + skip_containerd="true" + info "Containerd will be installed during the Docker installation ('-c' option ignored)" + fi + tool="docker" + fi + [ "$only_run_test" = "true" ] && test_installation "$tool" && return 0 setup "$cleanup" "$force" "$skip_containerd" @@ -795,13 +853,17 @@ handle_installation() "$force" \ "$enable_debug" + [ "$install_docker" = "true" ] && handle_docker + [ "$disable_test" = "false" ] && test_installation "$tool" - if [ "$skip_containerd" = "true" ] + if [ "$skip_containerd" = "true" ] && [ "$install_docker" = "false" ] then info "$kata_project is now installed" else - info "$kata_project and $containerd_project are now installed" + local extra_projects="containerd" + [ "$install_docker" = "true" ] && extra_projects+=" and docker" + info "$kata_project and $extra_projects are now installed" fi echo -e "\n${warnings}\n" @@ -823,17 +885,19 @@ handle_args() local disable_test="false" local only_run_test="false" local enable_debug="false" + local install_docker="false" local opt local kata_version="" local containerd_flavour="lts" - while getopts "c:dfhk:ortT" opt "$@" + while getopts "c:dDfhk:ortT" opt "$@" do case "$opt" in c) containerd_flavour="$OPTARG" ;; d) enable_debug="true" ;; + D) install_docker="true" ;; f) force="true" ;; h) usage; exit 0 ;; k) kata_version="$OPTARG" ;; @@ -861,7 +925,8 @@ handle_args() "$disable_test" \ "$only_run_test" \ "$kata_version" \ - "$containerd_flavour" + "$containerd_flavour" \ + "$install_docker" } main() From 5d10aed9bae2a285d68ddd1ed57d850efb908518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 6 Nov 2023 14:58:24 +0100 Subject: [PATCH 3/3] kata-manager: Make containerd_config a global var MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As "/etc/containerd/config.toml" is used from more than one place, let's just make it a global var. Signed-off-by: Fabiano FidĂȘncio --- utils/kata-manager.sh | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/utils/kata-manager.sh b/utils/kata-manager.sh index c9e70c7d7a..a70df88f18 100755 --- a/utils/kata-manager.sh +++ b/utils/kata-manager.sh @@ -45,6 +45,9 @@ readonly kata_clh_configuration="configuration-clh" # Systemd unit name for containerd daemon readonly containerd_service_name="containerd.service" +# Containerd configuration file +readonly containerd_config="/etc/containerd/config.toml" + # Directory in which to create symbolic links readonly link_dir=${link_dir:-/usr/bin} @@ -455,8 +458,6 @@ configure_containerd() info "Configuring $project" - local cfg="/etc/containerd/config.toml" - local systemd_unit_dir="/etc/systemd/system" sudo mkdir -p "$systemd_unit_dir" @@ -488,19 +489,19 @@ configure_containerd() fi # Backup the original containerd configuration: - sudo mkdir -p "$(dirname $cfg)" + sudo mkdir -p "$(dirname $containerd_config)" - sudo test -e "$cfg" || { - sudo touch "$cfg" - info "Created $cfg" + sudo test -e "$containerd_config" || { + sudo touch "$containerd_config" + info "Created $containerd_config" } local original - original="${cfg}-pre-kata-$(date -I)" + original="${containerd_config}-pre-kata-$(date -I)" - sudo grep -q "$kata_runtime_type" "$cfg" || { - sudo cp "$cfg" "${original}" - info "Backed up $cfg to $original" + sudo grep -q "$kata_runtime_type" "$containerd_config" || { + sudo cp "$containerd_config" "${original}" + info "Backed up $containerd_config to $original" } local modified="false" @@ -512,8 +513,8 @@ configure_containerd() "$(date -Iseconds)" \ "$script_name") - sudo grep -q "$kata_runtime_type" "$cfg" || { - cat <<-EOF | sudo tee -a "$cfg" + sudo grep -q "$kata_runtime_type" "$containerd_config" || { + cat <<-EOF | sudo tee -a "$containerd_config" # $comment_text [plugins] [plugins."io.containerd.grpc.v1.cri"] @@ -538,11 +539,11 @@ configure_containerd() if [ "$enable_debug" = "true" ] then local debug_enabled - debug_enabled=$(awk -v RS='' '/\[debug\]/' "$cfg" |\ + debug_enabled=$(awk -v RS='' '/\[debug\]/' "$containerd_config" |\ grep -E "^\s*\\s*=\s*.*\" || true) [ -n "$debug_enabled" ] || { - cat <<-EOF | sudo tee -a "$cfg" + cat <<-EOF | sudo tee -a "$containerd_config" # $comment_text [debug] level = "debug" @@ -552,7 +553,7 @@ configure_containerd() modified="true" fi - [ "$modified" = "true" ] && info "Modified $cfg" + [ "$modified" = "true" ] && info "Modified $containerd_config" sudo systemctl enable containerd sudo systemctl start containerd @@ -727,9 +728,7 @@ handle_docker() if [ "$ret" -eq 0 ] then info "Backing up previous $containerd_project configuration" - local cfg="/etc/containerd/config.toml" - - [ -e "$cfg" ] && sudo mv $cfg $cfg.system-$(date -Iseconds) + [ -e "$containerd_config" ] && sudo mv $containerd_config $containerd_config.system-$(date -Iseconds) fi containerd_installed