Merge pull request #8376 from fidencio/topic/kata-manager-add-support-for-docker-installation

kata-manager: Add support for Docker CLI installation
This commit is contained in:
Archana Shinde 2023-11-09 22:11:50 -08:00 committed by GitHub
commit 21e45bebc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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}
@ -244,6 +247,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 <version> : Specify Kata Containers version.
@ -454,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"
@ -487,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"
@ -511,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"]
@ -537,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*\<level\>\s*=\s*.*\<debug\>" || true)
[ -n "$debug_enabled" ] || {
cat <<-EOF | sudo tee -a "$cfg"
cat <<-EOF | sudo tee -a "$containerd_config"
# $comment_text
[debug]
level = "debug"
@ -551,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
@ -720,26 +722,69 @@ handle_containerd()
containerd --version
}
handle_docker()
{
{ 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
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 specified"
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 \
--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"
@ -777,7 +822,25 @@ handle_installation()
local kata_version="${7:-}"
local containerd_flavour="${8:-}"
[ "$only_run_test" = "true" ] && test_installation && return 0
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"
@ -789,13 +852,17 @@ handle_installation()
"$force" \
"$enable_debug"
[ "$disable_test" = "false" ] && test_installation
[ "$install_docker" = "true" ] && handle_docker
if [ "$skip_containerd" = "true" ]
[ "$disable_test" = "false" ] && test_installation "$tool"
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"
@ -817,17 +884,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" ;;
@ -855,7 +924,8 @@ handle_args()
"$disable_test" \
"$only_run_test" \
"$kata_version" \
"$containerd_flavour"
"$containerd_flavour" \
"$install_docker"
}
main()