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 # Systemd unit name for containerd daemon
readonly containerd_service_name="containerd.service" readonly containerd_service_name="containerd.service"
# Containerd configuration file
readonly containerd_config="/etc/containerd/config.toml"
# Directory in which to create symbolic links # Directory in which to create symbolic links
readonly link_dir=${link_dir:-/usr/bin} readonly link_dir=${link_dir:-/usr/bin}
@ -244,6 +247,7 @@ Options:
Find more details on LTS and Active versions of containerd on Find more details on LTS and Active versions of containerd on
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').
-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.
@ -454,8 +458,6 @@ configure_containerd()
info "Configuring $project" info "Configuring $project"
local cfg="/etc/containerd/config.toml"
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"
@ -487,19 +489,19 @@ configure_containerd()
fi fi
# Backup the original containerd configuration: # Backup the original containerd configuration:
sudo mkdir -p "$(dirname $cfg)" sudo mkdir -p "$(dirname $containerd_config)"
sudo test -e "$cfg" || { sudo test -e "$containerd_config" || {
sudo touch "$cfg" sudo touch "$containerd_config"
info "Created $cfg" info "Created $containerd_config"
} }
local original local original
original="${cfg}-pre-kata-$(date -I)" original="${containerd_config}-pre-kata-$(date -I)"
sudo grep -q "$kata_runtime_type" "$cfg" || { sudo grep -q "$kata_runtime_type" "$containerd_config" || {
sudo cp "$cfg" "${original}" sudo cp "$containerd_config" "${original}"
info "Backed up $cfg to $original" info "Backed up $containerd_config to $original"
} }
local modified="false" local modified="false"
@ -511,8 +513,8 @@ configure_containerd()
"$(date -Iseconds)" \ "$(date -Iseconds)" \
"$script_name") "$script_name")
sudo grep -q "$kata_runtime_type" "$cfg" || { sudo grep -q "$kata_runtime_type" "$containerd_config" || {
cat <<-EOF | sudo tee -a "$cfg" cat <<-EOF | sudo tee -a "$containerd_config"
# $comment_text # $comment_text
[plugins] [plugins]
[plugins."io.containerd.grpc.v1.cri"] [plugins."io.containerd.grpc.v1.cri"]
@ -537,11 +539,11 @@ configure_containerd()
if [ "$enable_debug" = "true" ] if [ "$enable_debug" = "true" ]
then then
local debug_enabled 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) grep -E "^\s*\<level\>\s*=\s*.*\<debug\>" || true)
[ -n "$debug_enabled" ] || { [ -n "$debug_enabled" ] || {
cat <<-EOF | sudo tee -a "$cfg" cat <<-EOF | sudo tee -a "$containerd_config"
# $comment_text # $comment_text
[debug] [debug]
level = "debug" level = "debug"
@ -551,7 +553,7 @@ configure_containerd()
modified="true" modified="true"
fi fi
[ "$modified" = "true" ] && info "Modified $cfg" [ "$modified" = "true" ] && info "Modified $containerd_config"
sudo systemctl enable containerd sudo systemctl enable containerd
sudo systemctl start containerd sudo systemctl start containerd
@ -720,26 +722,69 @@ handle_containerd()
containerd --version 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() test_installation()
{ {
local tool="${1:-}"
[ -z "$tool" ] && die "The tool to test $kata_project with was not specified"
info "Testing $kata_project\n" info "Testing $kata_project\n"
sudo kata-runtime check -v sudo kata-runtime check -v
local image="docker.io/library/busybox:latest" local image="docker.io/library/busybox:latest"
sudo ctr image pull "$image" sudo $tool image pull "$image"
local container_name="test-kata" local container_name="test-kata"
# Used to prove that the kernel in the container # Used to prove that the kernel in the container
# is different to the host kernel. # is different to the host kernel.
local container_kernel cmd="sudo $tool run --runtime "$kata_runtime_type" --rm"
container_kernel=$(sudo ctr run \ case "$tool" in
--runtime "$kata_runtime_type" \ docker)
--rm \ # docker takes the container name as `--name
"$image" \ # $container_name`, passed to the run option.
"$container_name" \ cmd+=" --name $container_name" ;;
uname -r || true) 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" [ -z "$container_kernel" ] && die "Failed to test $kata_project"
@ -777,7 +822,25 @@ handle_installation()
local kata_version="${7:-}" local kata_version="${7:-}"
local containerd_flavour="${8:-}" 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" setup "$cleanup" "$force" "$skip_containerd"
@ -789,13 +852,17 @@ handle_installation()
"$force" \ "$force" \
"$enable_debug" "$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 then
info "$kata_project is now installed" info "$kata_project is now installed"
else 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 fi
echo -e "\n${warnings}\n" echo -e "\n${warnings}\n"
@ -817,17 +884,19 @@ handle_args()
local disable_test="false" local disable_test="false"
local only_run_test="false" local only_run_test="false"
local enable_debug="false" local enable_debug="false"
local install_docker="false"
local opt local opt
local kata_version="" local kata_version=""
local containerd_flavour="lts" local containerd_flavour="lts"
while getopts "c:dfhk:ortT" opt "$@" while getopts "c:dDfhk:ortT" opt "$@"
do do
case "$opt" in case "$opt" in
c) containerd_flavour="$OPTARG" ;; c) containerd_flavour="$OPTARG" ;;
d) enable_debug="true" ;; d) enable_debug="true" ;;
D) install_docker="true" ;;
f) force="true" ;; f) force="true" ;;
h) usage; exit 0 ;; h) usage; exit 0 ;;
k) kata_version="$OPTARG" ;; k) kata_version="$OPTARG" ;;
@ -855,7 +924,8 @@ handle_args()
"$disable_test" \ "$disable_test" \
"$only_run_test" \ "$only_run_test" \
"$kata_version" \ "$kata_version" \
"$containerd_flavour" "$containerd_flavour" \
"$install_docker"
} }
main() main()