-
Notifications
You must be signed in to change notification settings - Fork 195
ci: Add test cases for CoCo image pulling without forked containerd #5764
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,7 @@ case "${CI_JOB}" in | |
export AA_KBC="offline_fs_kbc" | ||
if [[ "${CI_JOB}" =~ K8S ]]; then | ||
export KUBERNETES=yes | ||
export SNAPSHOTTER="nydus" | ||
fi | ||
;; | ||
esac | ||
|
@@ -191,6 +192,7 @@ case "${CI_JOB}" in | |
if grep -q 'prot_virt=1' /proc/cmdline && grep -Eq '^facilities.* 158 .*' /proc/cpuinfo; then | ||
export TEE_TYPE="se" | ||
fi | ||
export SNAPSHOTTER="nydus" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This placement means that the nydus snapshotter isn't set for TDX, is that correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. The tdx kernel is not support to sharing images now. |
||
fi | ||
|
||
if [[ "${CI_JOB}" =~ CLOUD_HYPERVISOR ]]; then | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -17,6 +17,8 @@ script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |||||||||||||||||||||
# Flag to do tasks for CI | ||||||||||||||||||||||
CI=${CI:-""} | ||||||||||||||||||||||
|
||||||||||||||||||||||
SNAPSHOTTER=${SNAPSHOTTER:-""} | ||||||||||||||||||||||
|
||||||||||||||||||||||
# shellcheck source=./lib.sh | ||||||||||||||||||||||
source "${script_dir}/lib.sh" | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -81,17 +83,42 @@ install_from_static_tarball() { | |||||||||||||||||||||
sudo tar -xvf "${tarball_name}" -C / | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
install_vanilla_from_static_tarball() { | ||||||||||||||||||||||
echo "Trying to install containerd from static tarball" | ||||||||||||||||||||||
local tarball_url="https://github.com/containerd/containerd/releases/download" | ||||||||||||||||||||||
local containerd_tarball_version="v1.7.0" | ||||||||||||||||||||||
local containerd_version=${containerd_tarball_version#v} | ||||||||||||||||||||||
local tarball_name="containerd-${containerd_version}-${CONTAINERD_OS}-${CONTAINERD_ARCH}.tar.gz" | ||||||||||||||||||||||
local url="${tarball_url}/${containerd_tarball_version}/${tarball_name}" | ||||||||||||||||||||||
|
||||||||||||||||||||||
echo "Download tarball from ${url}" | ||||||||||||||||||||||
if ! curl -OL -f "${url}"; then | ||||||||||||||||||||||
echo "Failed to download tarball from ${url}" | ||||||||||||||||||||||
return 1 | ||||||||||||||||||||||
fi | ||||||||||||||||||||||
|
||||||||||||||||||||||
tmp_dir=$(mktemp -d -t install-vanilla-containerd-tmp.XXXXXXXXXX) | ||||||||||||||||||||||
sudo tar -xvf "${tarball_name}" -C $tmp_dir/ | ||||||||||||||||||||||
sudo install -D -m 755 "$tmp_dir/bin/containerd" "/usr/local/bin/containerd-vanilla" | ||||||||||||||||||||||
|
||||||||||||||||||||||
systemctl status containerd | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
install_cri-tools() { | ||||||||||||||||||||||
crictl_repo=$(get_version "externals.critools.url") | ||||||||||||||||||||||
crictl_version=$(get_version "externals.critools.version") | ||||||||||||||||||||||
crictl_tag_prefix="v" | ||||||||||||||||||||||
crictl_repo=$(get_version "externals.critools.url") | ||||||||||||||||||||||
crictl_version=$(get_version "externals.critools.version") | ||||||||||||||||||||||
crictl_tag_prefix="v" | ||||||||||||||||||||||
|
||||||||||||||||||||||
crictl_url="${crictl_repo}/releases/download/v${crictl_version}/crictl-${crictl_tag_prefix}${crictl_version}-linux-$(${script_dir}/kata-arch.sh -g).tar.gz" | ||||||||||||||||||||||
curl -Ls "$crictl_url" | sudo tar xfz - -C /usr/local/bin | ||||||||||||||||||||||
crictl_url="${crictl_repo}/releases/download/v${crictl_version}/crictl-${crictl_tag_prefix}${crictl_version}-linux-$(${script_dir}/kata-arch.sh -g).tar.gz" | ||||||||||||||||||||||
curl -Ls "$crictl_url" | sudo tar xfz - -C /usr/local/bin | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
install_from_static_tarball || install_from_source | ||||||||||||||||||||||
|
||||||||||||||||||||||
if [ "${SNAPSHOTTER}" == "nydus" ]; then | ||||||||||||||||||||||
install_vanilla_from_static_tarball | ||||||||||||||||||||||
fi | ||||||||||||||||||||||
Comment on lines
116
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably a change for the follow up PR that splits the jobs, but do we still want to have the forked containerd installed if we are using nydus, otherwise we could do something like
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. |
||||||||||||||||||||||
|
||||||||||||||||||||||
install_cri-tools | ||||||||||||||||||||||
|
||||||||||||||||||||||
sudo systemctl daemon-reload |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (c) 2023 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
set -o errtrace | ||
|
||
cidir=$(dirname "$0") | ||
source "${cidir}/lib.sh" | ||
|
||
target_dir="/opt/kata" | ||
|
||
nydus_snapshotter_repo=${nydus_snapshotter_repo:-"github.com/containerd/nydus-snapshotter"} | ||
nydus_snapshotter_repo_git="https://${nydus_snapshotter_repo}.git" | ||
nydus_snapshotter_version=${nydus_snapshotter_version:-"v0.12.0"} | ||
nydus_snapshotter_repo_dir="${GOPATH}/src/${nydus_snapshotter_repo}" | ||
nydus_snapshotter_binary_target_dir="$target_dir/bin" | ||
nydus_snapshotter_config_target_dir="$target_dir/share/nydus-snapshotter" | ||
|
||
nydus_repo=${nydus_repo:-"https://github.com/dragonflyoss/image-service"} | ||
nydus_version=${nydus_version:-"v2.2.3"} | ||
|
||
arch="$(uname -m)" | ||
|
||
clone_nydus_snapshotter_repo() { | ||
add_repo_to_git_safe_directory "${nydus_snapshotter_repo_dir}" | ||
|
||
if [ ! -d "${nydus_snapshotter_repo_dir}" ]; then | ||
sudo mkdir -p "${nydus_snapshotter_repo_dir}" | ||
sudo git clone ${nydus_snapshotter_repo_git} "${nydus_snapshotter_repo_dir}" || true | ||
pushd "${nydus_snapshotter_repo_dir}" | ||
sudo git checkout "${nydus_snapshotter_version}" | ||
popd | ||
fi | ||
} | ||
|
||
build_nydus_snapshotter() { | ||
pushd "${nydus_snapshotter_repo_dir}" | ||
if [ "$arch" = "s390x" ]; then | ||
export GOARCH=$arch | ||
fi | ||
sudo -E PATH=$PATH make | ||
|
||
sudo install -D -m 755 "bin/containerd-nydus-grpc" "$nydus_snapshotter_binary_target_dir/containerd-nydus-grpc" | ||
sudo install -D -m 755 "bin/nydus-overlayfs" "$nydus_snapshotter_binary_target_dir/nydus-overlayfs" | ||
if [ ! -f "/usr/local/bin/nydus-overlayfs" ]; then | ||
echo " /usr/local/bin/nydus-overlayfs exists, now we will replace it." | ||
sudo cp "$nydus_snapshotter_binary_target_dir/nydus-overlayfs" "/usr/local/bin/nydus-overlayfs" | ||
fi | ||
sudo rm -rf "$nydus_snapshotter_repo_dir/bin" | ||
popd >/dev/null | ||
} | ||
|
||
download_nydus_snapshotter_config() { | ||
tmp_dir=$(mktemp -d -t install-nydus-snapshotter-config-tmp.XXXXXXXXXX) | ||
sudo curl -L https://raw.githubusercontent.com/containerd/nydus-snapshotter/main/misc/snapshotter/config-coco-guest-pulling.toml -o "$tmp_dir/config-coco-guest-pulling.toml" | ||
sudo curl -L https://raw.githubusercontent.com/containerd/nydus-snapshotter/main/misc/snapshotter/config-coco-host-sharing.toml -o "$tmp_dir/config-coco-host-sharing.toml" | ||
sudo install -D -m 644 "$tmp_dir/config-coco-guest-pulling.toml" "$nydus_snapshotter_config_target_dir/config-coco-guest-pulling.toml" | ||
sudo install -D -m 644 "$tmp_dir/config-coco-host-sharing.toml" "$nydus_snapshotter_config_target_dir/config-coco-host-sharing.toml" | ||
|
||
} | ||
|
||
download_nydus_from_tarball() { | ||
if [ "$arch" = "s390x" ]; then | ||
echo "Skip to download nydus for $arch, it doesn't work for $arch now." | ||
return | ||
fi | ||
local goarch="$(${cidir}/kata-arch.sh --golang)" | ||
local tarball_url="${nydus_repo}/releases/download/${nydus_version}/nydus-static-${nydus_version}-linux-$goarch.tgz" | ||
echo "Download tarball from ${tarball_url}" | ||
tmp_dir=$(mktemp -d -t install-nydus-tmp.XXXXXXXXXX) | ||
sudo curl -Ls "$tarball_url" | sudo tar xfz - -C $tmp_dir --strip-components=1 | ||
sudo install -D -m 755 "$tmp_dir/nydus-image" "/usr/local/bin/" | ||
} | ||
|
||
download_nydus_from_tarball | ||
clone_nydus_snapshotter_repo | ||
build_nydus_snapshotter | ||
download_nydus_snapshotter_config | ||
echo "install nydus-snapshotter successful" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,10 @@ source "${BATS_TEST_DIRNAME}/../../../lib/common.bash" | |
source "${BATS_TEST_DIRNAME}/../../../.ci/lib.sh" | ||
FIXTURES_DIR="${BATS_TEST_DIRNAME}/fixtures" | ||
SHARED_FIXTURES_DIR="${BATS_TEST_DIRNAME}/../../confidential/fixtures" | ||
NYDUS_SNAPSHOTTER_BINARY="/opt/kata/bin/containerd-nydus-grpc" | ||
NYDUS_SNAPSHOTTER_TARFS_CONFIG="/opt/kata/share/nydus-snapshotter/config-coco-host-sharing.toml" | ||
NYDUS_SNAPSHOTTER_GUEST_CONFIG="/opt/kata/share/nydus-snapshotter/config-coco-guest-pulling.toml" | ||
NYDUS_SNAPSHOTTER_CONFIG="$NYDUS_SNAPSHOTTER_TARFS_CONFIG" | ||
|
||
# Toggle between true and false the service_offload configuration of | ||
# the Kata agent. | ||
|
@@ -180,6 +184,13 @@ disable_full_debug() { | |
sudo sed -i -e 's/^# *\(enable_debug\).*=.*$/\1 = false/g' "$RUNTIME_CONFIG_PATH" | ||
} | ||
|
||
restart_containerd() { | ||
sudo systemctl restart containerd | ||
if ! waitForProcess 30 5 "sudo crictl info >/dev/null"; then | ||
die "containerd seems not operational after restarted" | ||
fi | ||
} | ||
|
||
# Configure containerd for confidential containers. Among other things, it ensures | ||
# the CRI handler is configured to deal with confidential container. | ||
# | ||
|
@@ -198,15 +209,15 @@ configure_cc_containerd() { | |
# installed via operator it will assume containerd is in right state | ||
# already. | ||
[ "${TESTS_CONFIGURE_CC_CONTAINERD:-yes}" == "yes" ] || return 0 | ||
sudo iptables -w -P FORWARD ACCEPT | ||
|
||
# Even if we are not saving the original file it is a good idea to | ||
# restart containerd because it might be in an inconsistent state here. | ||
sudo systemctl stop containerd | ||
sleep 5 | ||
sleep 10 | ||
[ -n "$saved_containerd_conf_file" ] && \ | ||
sudo cp -f "$containerd_conf_file" "$saved_containerd_conf_file" | ||
sudo systemctl start containerd | ||
waitForProcess 30 5 "sudo crictl info >/dev/null" | ||
restart_containerd | ||
|
||
# Ensure the cc CRI handler is set. | ||
local cri_handler=$(sudo crictl info | \ | ||
|
@@ -223,11 +234,6 @@ configure_cc_containerd() { | |
sudo tee -a "$containerd_conf_file" | ||
fi | ||
|
||
sudo systemctl restart containerd | ||
if ! waitForProcess 30 5 "sudo crictl info >/dev/null"; then | ||
die "containerd seems not operational after reconfigured" | ||
fi | ||
sudo iptables -w -P FORWARD ACCEPT | ||
} | ||
|
||
# | ||
|
@@ -445,3 +451,91 @@ EOF | |
EOF | ||
fi | ||
} | ||
|
||
############################################################################### | ||
|
||
# remote-snapshotter | ||
|
||
EXPORT_MODE=${EXPORT_MODE:-"image_guest_pull"} | ||
|
||
configure_remote_snapshotter() { | ||
case "${SNAPSHOTTER}" in | ||
"nydus") | ||
configure_nydus_snapshotter | ||
;; | ||
*) ;; | ||
|
||
esac | ||
} | ||
|
||
is_containerd_support_per_runtime_snapshotter() { | ||
containerd_version=$(containerd --version | awk '{print $3}') | ||
required_version="v1.7.0" | ||
printf '%s\n' ${required_version} ${containerd_version} | sort --check=quiet -V | ||
} | ||
|
||
set_vanilla_containerd() { | ||
sudo systemctl stop containerd | ||
sleep 10 | ||
sudo mv -f /usr/local/bin/containerd /usr/local/bin/containerd-coco | ||
sudo cp -f /usr/local/bin/containerd-vanilla /usr/local/bin/containerd | ||
echo "vanilla containerd version: $(containerd --version | awk '{print $3}')" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to restart containerd's service at this point? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Containerd would be restarted in |
||
restart_containerd | ||
} | ||
|
||
unset_vanilla_containerd() { | ||
sudo systemctl stop containerd | ||
sleep 10 | ||
sudo rm -f /usr/local/bin/containerd | ||
sudo mv -f /usr/local/bin/containerd-coco /usr/local/bin/containerd | ||
echo "coco containerd version: $(containerd --version | awk '{print $3}')" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to restart containerd's service at this point? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Containerd would be restarted in |
||
restart_containerd | ||
} | ||
|
||
configure_containerd_for_nydus_snapshotter() { | ||
set_vanilla_containerd | ||
local containerd_config="$1" | ||
snapshotter_socket="/run/containerd-nydus/containerd-nydus-grpc.sock" | ||
proxy_config=" [proxy_plugins.$SNAPSHOTTER]\n type = \"snapshot\"\n address = \"${snapshotter_socket}\"" | ||
|
||
if grep -q "\[proxy_plugins\]" "$containerd_config"; then | ||
sudo sed -i '/\[proxy_plugins\]/a\'"$proxy_config" "$containerd_config" | ||
else | ||
sudo echo -e "[proxy_plugins]" >>"$containerd_config" | ||
sudo echo -e "$proxy_config" >>"$containerd_config" | ||
fi | ||
|
||
sudo sed -i 's/disable_snapshot_annotations = .*/disable_snapshot_annotations = false/g' "$containerd_config" | ||
sudo sed -i 's/snapshotter = .*/snapshotter = "nydus"/g' "$containerd_config" | ||
} | ||
|
||
kill_nydus_snapshotter_process() { | ||
echo "Kill nydus snapshotter" | ||
bin="containerd-nydus-grpc" | ||
sudo kill -9 $(pidof $bin) || true | ||
sudo rm -rf "/var/lib/containerd-nydus" || true | ||
} | ||
|
||
remove_test_image() { | ||
local test_image="$1" | ||
crictl rmi "$1" | ||
pause_name=$(crictl images -o json | jq -r '.images[].repoTags[] | select(. | contains("pause"))') | ||
crictl rmi "$pause_name" | ||
} | ||
|
||
restart_nydus_snapshotter() { | ||
kill_nydus_snapshotter_process || true | ||
echo "Restart nydus snapshotter" | ||
sudo "$NYDUS_SNAPSHOTTER_BINARY" --config "$NYDUS_SNAPSHOTTER_CONFIG" >/dev/stdout 2>&1 & | ||
} | ||
|
||
configure_nydus_snapshotter() { | ||
echo "Configure nydus snapshotter" | ||
if [ "$EXPORT_MODE" == "image_guest_pull" ]; then | ||
NYDUS_SNAPSHOTTER_CONFIG="$NYDUS_SNAPSHOTTER_GUEST_CONFIG" | ||
else | ||
NYDUS_SNAPSHOTTER_CONFIG="$NYDUS_SNAPSHOTTER_TARFS_CONFIG" | ||
sudo sed -i "s/export_mode = .*/export_mode = \"$EXPORT_MODE\"/" "$NYDUS_SNAPSHOTTER_CONFIG" | ||
fi | ||
restart_nydus_snapshotter | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this snapshotter job flag might need to be re-worked as part of the new job that Fabiano and others have discussed, but it's probably fine for now.