mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-26 15:32:30 +00:00
Merge pull request #3858 from jodh-intel/kata-manager-add-more-options
Add debug and self-test control options to Kata Manager
This commit is contained in:
commit
095bc2d50a
@ -43,7 +43,7 @@ readonly link_dir=${link_dir:-/usr/bin}
|
|||||||
|
|
||||||
readonly tmpdir=$(mktemp -d)
|
readonly tmpdir=$(mktemp -d)
|
||||||
|
|
||||||
readonly warnings=$(cat <<EOT
|
readonly warnings=$(cat <<EOF
|
||||||
WARNINGS:
|
WARNINGS:
|
||||||
|
|
||||||
- Use distro-packages where possible
|
- Use distro-packages where possible
|
||||||
@ -63,7 +63,7 @@ WARNINGS:
|
|||||||
and $containerd_project from binary release packages. These versions may
|
and $containerd_project from binary release packages. These versions may
|
||||||
not have been tested with your distribution version.
|
not have been tested with your distribution version.
|
||||||
|
|
||||||
EOT
|
EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
die()
|
die()
|
||||||
@ -199,7 +199,7 @@ github_download_release()
|
|||||||
|
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
cat <<EOT
|
cat <<EOF
|
||||||
Usage: $script_name [options] [<kata-version> [<containerd-version>]]
|
Usage: $script_name [options] [<kata-version> [<containerd-version>]]
|
||||||
|
|
||||||
Description: Install $kata_project [1] (and optionally $containerd_project [2])
|
Description: Install $kata_project [1] (and optionally $containerd_project [2])
|
||||||
@ -208,11 +208,14 @@ Description: Install $kata_project [1] (and optionally $containerd_project [2])
|
|||||||
Options:
|
Options:
|
||||||
|
|
||||||
-c <version> : Specify containerd version.
|
-c <version> : Specify containerd version.
|
||||||
|
-d : Enable debug for all components.
|
||||||
-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.
|
||||||
-o : Only install Kata Containers.
|
-o : Only install Kata Containers.
|
||||||
-r : Don't cleanup on failure (retain files).
|
-r : Don't cleanup on failure (retain files).
|
||||||
|
-t : Disable self test (don't try to create a container after install).
|
||||||
|
-T : Only run self test (do not install anything).
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
@ -232,7 +235,7 @@ Advice:
|
|||||||
|
|
||||||
$ kata-runtime check --only-list-releases
|
$ kata-runtime check --only-list-releases
|
||||||
|
|
||||||
EOT
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
# Determine if the system only supports cgroups v2.
|
# Determine if the system only supports cgroups v2.
|
||||||
@ -402,13 +405,21 @@ install_containerd()
|
|||||||
|
|
||||||
sudo tar -C /usr/local -xvf "${file}"
|
sudo tar -C /usr/local -xvf "${file}"
|
||||||
|
|
||||||
sudo ln -sf /usr/local/bin/ctr "${link_dir}"
|
for file in \
|
||||||
|
/usr/local/bin/containerd \
|
||||||
|
/usr/local/bin/ctr
|
||||||
|
do
|
||||||
|
sudo ln -sf "$file" "${link_dir}"
|
||||||
|
done
|
||||||
|
|
||||||
info "$project installed\n"
|
info "$project installed\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
configure_containerd()
|
configure_containerd()
|
||||||
{
|
{
|
||||||
|
local enable_debug="${1:-}"
|
||||||
|
[ -z "$enable_debug" ] && die "no enable debug value"
|
||||||
|
|
||||||
local project="$containerd_project"
|
local project="$containerd_project"
|
||||||
|
|
||||||
info "Configuring $project"
|
info "Configuring $project"
|
||||||
@ -436,7 +447,6 @@ configure_containerd()
|
|||||||
"$(date -Iseconds)" |\
|
"$(date -Iseconds)" |\
|
||||||
tee -a "$containerd_service_name"
|
tee -a "$containerd_service_name"
|
||||||
|
|
||||||
|
|
||||||
sudo cp "${containerd_service_name}" "${dest}"
|
sudo cp "${containerd_service_name}" "${dest}"
|
||||||
sudo systemctl daemon-reload
|
sudo systemctl daemon-reload
|
||||||
|
|
||||||
@ -460,26 +470,55 @@ configure_containerd()
|
|||||||
info "Backed up $cfg to $original"
|
info "Backed up $cfg to $original"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local modified="false"
|
||||||
|
|
||||||
# Add the Kata Containers configuration details:
|
# Add the Kata Containers configuration details:
|
||||||
|
|
||||||
sudo grep -q "$kata_runtime_type" "$cfg" || {
|
local comment_text
|
||||||
cat <<-EOT | sudo tee -a "$cfg"
|
comment_text=$(printf "%s: Added by %s\n" \
|
||||||
[plugins]
|
"$(date -Iseconds)" \
|
||||||
[plugins."io.containerd.grpc.v1.cri"]
|
"$script_name")
|
||||||
[plugins."io.containerd.grpc.v1.cri".containerd]
|
|
||||||
default_runtime_name = "${kata_runtime_name}"
|
|
||||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
|
|
||||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.${kata_runtime_name}]
|
|
||||||
runtime_type = "${kata_runtime_type}"
|
|
||||||
EOT
|
|
||||||
|
|
||||||
info "Modified $cfg"
|
sudo grep -q "$kata_runtime_type" "$cfg" || {
|
||||||
|
cat <<-EOF | sudo tee -a "$cfg"
|
||||||
|
# $comment_text
|
||||||
|
[plugins]
|
||||||
|
[plugins."io.containerd.grpc.v1.cri"]
|
||||||
|
[plugins."io.containerd.grpc.v1.cri".containerd]
|
||||||
|
default_runtime_name = "${kata_runtime_name}"
|
||||||
|
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
|
||||||
|
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.${kata_runtime_name}]
|
||||||
|
runtime_type = "${kata_runtime_type}"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
modified="true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if [ "$enable_debug" = "true" ]
|
||||||
|
then
|
||||||
|
local debug_enabled
|
||||||
|
debug_enabled=$(awk -v RS='' '/\[debug\]/' "$cfg" |\
|
||||||
|
grep -E "^\s*\<level\>\s*=\s*.*\<debug\>" || true)
|
||||||
|
|
||||||
|
[ -n "$debug_enabled" ] || {
|
||||||
|
cat <<-EOF | sudo tee -a "$cfg"
|
||||||
|
# $comment_text
|
||||||
|
[debug]
|
||||||
|
level = "debug"
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
modified="true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ "$modified" = "true" ] && info "Modified $cfg"
|
||||||
sudo systemctl enable containerd
|
sudo systemctl enable containerd
|
||||||
sudo systemctl start containerd
|
sudo systemctl start containerd
|
||||||
|
|
||||||
info "Configured $project\n"
|
local msg="disabled"
|
||||||
|
[ "$enable_debug" = "true" ] && msg="enabled"
|
||||||
|
|
||||||
|
info "Configured $project (debug $msg)\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
install_kata()
|
install_kata()
|
||||||
@ -540,11 +579,48 @@ install_kata()
|
|||||||
info "$project installed\n"
|
info "$project installed\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configure_kata()
|
||||||
|
{
|
||||||
|
local enable_debug="${1:-}"
|
||||||
|
[ -z "$enable_debug" ] && die "no enable debug value"
|
||||||
|
|
||||||
|
[ "$enable_debug" = "false" ] && \
|
||||||
|
info "Using default $kata_project configuration" && \
|
||||||
|
return 0
|
||||||
|
|
||||||
|
local config_file='configuration.toml'
|
||||||
|
local kata_dir='/etc/kata-containers'
|
||||||
|
|
||||||
|
sudo mkdir -p "$kata_dir"
|
||||||
|
|
||||||
|
local cfg_from
|
||||||
|
local cfg_to
|
||||||
|
|
||||||
|
cfg_from="${kata_install_dir}/share/defaults/kata-containers/${config_file}"
|
||||||
|
cfg_to="${kata_dir}/${config_file}"
|
||||||
|
|
||||||
|
[ -e "$cfg_from" ] || die "cannot find $kata_project configuration file"
|
||||||
|
|
||||||
|
sudo install -o root -g root -m 0644 "$cfg_from" "$cfg_to"
|
||||||
|
|
||||||
|
sudo sed -i \
|
||||||
|
-e 's/^# *\(enable_debug\).*=.*$/\1 = true/g' \
|
||||||
|
-e 's/^kernel_params = "\(.*\)"/kernel_params = "\1 agent.log=debug initcall_debug"/g' \
|
||||||
|
"$cfg_to"
|
||||||
|
|
||||||
|
info "Configured $kata_project for full debug (delete $cfg_to to use pristine $kata_project configuration)"
|
||||||
|
}
|
||||||
|
|
||||||
handle_kata()
|
handle_kata()
|
||||||
{
|
{
|
||||||
local version="${1:-}"
|
local version="${1:-}"
|
||||||
|
|
||||||
install_kata "$version"
|
local enable_debug="${2:-}"
|
||||||
|
[ -z "$enable_debug" ] && die "no enable debug value"
|
||||||
|
|
||||||
|
install_kata "$version" "$enable_debug"
|
||||||
|
|
||||||
|
configure_kata "$enable_debug"
|
||||||
|
|
||||||
kata-runtime --version
|
kata-runtime --version
|
||||||
}
|
}
|
||||||
@ -556,6 +632,9 @@ handle_containerd()
|
|||||||
local force="${2:-}"
|
local force="${2:-}"
|
||||||
[ -z "$force" ] && die "need force value"
|
[ -z "$force" ] && die "need force value"
|
||||||
|
|
||||||
|
local enable_debug="${3:-}"
|
||||||
|
[ -z "$enable_debug" ] && die "no enable debug value"
|
||||||
|
|
||||||
local ret
|
local ret
|
||||||
|
|
||||||
if [ "$force" = "true" ]
|
if [ "$force" = "true" ]
|
||||||
@ -572,7 +651,7 @@ handle_containerd()
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
configure_containerd
|
configure_containerd "$enable_debug"
|
||||||
|
|
||||||
containerd --version
|
containerd --version
|
||||||
}
|
}
|
||||||
@ -617,20 +696,32 @@ handle_installation()
|
|||||||
local only_kata="${3:-}"
|
local only_kata="${3:-}"
|
||||||
[ -z "$only_kata" ] && die "no only Kata value"
|
[ -z "$only_kata" ] && die "no only Kata value"
|
||||||
|
|
||||||
|
local enable_debug="${4:-}"
|
||||||
|
[ -z "$enable_debug" ] && die "no enable debug value"
|
||||||
|
|
||||||
|
local disable_test="${5:-}"
|
||||||
|
[ -z "$disable_test" ] && die "no disable test value"
|
||||||
|
|
||||||
|
local only_run_test="${6:-}"
|
||||||
|
[ -z "$only_run_test" ] && die "no only run test value"
|
||||||
|
|
||||||
# These params can be blank
|
# These params can be blank
|
||||||
local kata_version="${4:-}"
|
local kata_version="${7:-}"
|
||||||
local containerd_version="${5:-}"
|
local containerd_version="${8:-}"
|
||||||
|
|
||||||
|
[ "$only_run_test" = "true" ] && test_installation && return 0
|
||||||
|
|
||||||
setup "$cleanup" "$force"
|
setup "$cleanup" "$force"
|
||||||
|
|
||||||
handle_kata "$kata_version"
|
handle_kata "$kata_version" "$enable_debug"
|
||||||
|
|
||||||
[ "$only_kata" = "false" ] && \
|
[ "$only_kata" = "false" ] && \
|
||||||
handle_containerd \
|
handle_containerd \
|
||||||
"$containerd_version" \
|
"$containerd_version" \
|
||||||
"$force"
|
"$force" \
|
||||||
|
"$enable_debug"
|
||||||
|
|
||||||
test_installation
|
[ "$disable_test" = "false" ] && test_installation
|
||||||
|
|
||||||
if [ "$only_kata" = "true" ]
|
if [ "$only_kata" = "true" ]
|
||||||
then
|
then
|
||||||
@ -647,21 +738,27 @@ handle_args()
|
|||||||
local cleanup="true"
|
local cleanup="true"
|
||||||
local force="false"
|
local force="false"
|
||||||
local only_kata="false"
|
local only_kata="false"
|
||||||
|
local disable_test="false"
|
||||||
|
local only_run_test="false"
|
||||||
|
local enable_debug="false"
|
||||||
|
|
||||||
local opt
|
local opt
|
||||||
|
|
||||||
local kata_version=""
|
local kata_version=""
|
||||||
local containerd_version=""
|
local containerd_version=""
|
||||||
|
|
||||||
while getopts "c:fhk:or" opt "$@"
|
while getopts "c:dfhk:ortT" opt "$@"
|
||||||
do
|
do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
c) containerd_version="$OPTARG" ;;
|
c) containerd_version="$OPTARG" ;;
|
||||||
|
d) enable_debug="true" ;;
|
||||||
f) force="true" ;;
|
f) force="true" ;;
|
||||||
h) usage; exit 0 ;;
|
h) usage; exit 0 ;;
|
||||||
k) kata_version="$OPTARG" ;;
|
k) kata_version="$OPTARG" ;;
|
||||||
o) only_kata="true" ;;
|
o) only_kata="true" ;;
|
||||||
r) cleanup="false" ;;
|
r) cleanup="false" ;;
|
||||||
|
t) disable_test="true" ;;
|
||||||
|
T) only_run_test="true" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -674,6 +771,9 @@ handle_args()
|
|||||||
"$cleanup" \
|
"$cleanup" \
|
||||||
"$force" \
|
"$force" \
|
||||||
"$only_kata" \
|
"$only_kata" \
|
||||||
|
"$enable_debug" \
|
||||||
|
"$disable_test" \
|
||||||
|
"$only_run_test" \
|
||||||
"$kata_version" \
|
"$kata_version" \
|
||||||
"$containerd_version"
|
"$containerd_version"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user