Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit ee2a7f5

Browse files
ChengyuZhu6fidencio
authored andcommitted
lib.sh: Split containerd restart from configure_cc_containerd
Let's do this as that will make it easier for configuring / reconfiguring containerd, which will be necessary in the coming up commits / PRs. And here we're also adapting the previous tests to using this change. Signed-off-by: ChengyuZhu6 <[email protected]>
1 parent 16b6644 commit ee2a7f5

File tree

7 files changed

+40
-19
lines changed

7 files changed

+40
-19
lines changed

integration/confidential/lib.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ disable_full_debug() {
180180
sudo sed -i -e 's/^# *\(enable_debug\).*=.*$/\1 = false/g' "$RUNTIME_CONFIG_PATH"
181181
}
182182

183+
restart_containerd() {
184+
sudo systemctl restart containerd
185+
if ! waitForProcess 30 5 "sudo crictl info >/dev/null"; then
186+
die "containerd seems not operational after restarted"
187+
fi
188+
}
189+
183190
# Configure containerd for confidential containers. Among other things, it ensures
184191
# the CRI handler is configured to deal with confidential container.
185192
#
@@ -198,15 +205,15 @@ configure_cc_containerd() {
198205
# installed via operator it will assume containerd is in right state
199206
# already.
200207
[ "${TESTS_CONFIGURE_CC_CONTAINERD:-yes}" == "yes" ] || return 0
208+
sudo iptables -w -P FORWARD ACCEPT
201209

202210
# Even if we are not saving the original file it is a good idea to
203211
# restart containerd because it might be in an inconsistent state here.
204212
sudo systemctl stop containerd
205213
sleep 5
206214
[ -n "$saved_containerd_conf_file" ] && \
207215
sudo cp -f "$containerd_conf_file" "$saved_containerd_conf_file"
208-
sudo systemctl start containerd
209-
waitForProcess 30 5 "sudo crictl info >/dev/null"
216+
restart_containerd
210217

211218
# Ensure the cc CRI handler is set.
212219
local cri_handler=$(sudo crictl info | \
@@ -223,11 +230,7 @@ configure_cc_containerd() {
223230
sudo tee -a "$containerd_conf_file"
224231
fi
225232

226-
sudo systemctl restart containerd
227-
if ! waitForProcess 30 5 "sudo crictl info >/dev/null"; then
228-
die "containerd seems not operational after reconfigured"
229-
fi
230-
sudo iptables -w -P FORWARD ACCEPT
233+
restart_containerd
231234
}
232235

233236
#

integration/containerd/confidential/tests_common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ setup_common() {
2525

2626
echo "Prepare containerd for Confidential Container"
2727
SAVED_CONTAINERD_CONF_FILE="/etc/containerd/config.toml.$$"
28-
configure_cc_containerd "$SAVED_CONTAINERD_CONF_FILE"
2928

29+
restart_containerd
3030
# Note: ensure that intructions changing the kernel parameters are
3131
# executed *after* saving the original list.
3232
saved_kernel_params=$(get_kernel_params)

integration/kubernetes/confidential/agent_image.bats

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ RUNTIMECLASS="${RUNTIMECLASS:-kata}"
3131
test_tag="[cc][agent][kubernetes][containerd]"
3232

3333
setup() {
34-
setup_common
34+
setup_containerd
35+
restart_containerd
36+
reconfigure_kata
3537
}
3638

3739
@test "$test_tag Test can launch pod with measured boot enabled" {

integration/kubernetes/confidential/sealed_secret.bats

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,8 @@ setup() {
2222
SAVED_CONTAINERD_CONF_FILE="/etc/containerd/config.toml.$$"
2323
configure_cc_containerd "$SAVED_CONTAINERD_CONF_FILE"
2424

25-
echo "Reconfigure Kata Containers"
26-
switch_image_service_offload on
27-
clear_kernel_params
28-
add_kernel_params "${original_kernel_params}"
29-
30-
setup_proxy
31-
switch_measured_rootfs_verity_scheme none
25+
restart_containerd
26+
reconfigure_kata
3227

3328
kubectl delete secret sealed-secret --ignore-not-found
3429
# Sealed secret format is defined at: https://github.com/confidential-containers/guest-components/blob/main/confidential-data-hub/docs/SEALED_SECRET.md#vault

integration/kubernetes/confidential/sev.bats

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ load "${BATS_TEST_DIRNAME}/../../confidential/lib.sh"
2525
load "${TESTS_REPO_DIR}/lib/common.bash"
2626
load "${TESTS_REPO_DIR}/integration/kubernetes/lib.sh"
2727
load "${TESTS_REPO_DIR}/integration/kubernetes/confidential/lib.sh"
28+
load "${BATS_TEST_DIRNAME}/tests_common.sh"
2829

2930
# Delete all test services
3031
k8s_delete_all() {
@@ -54,7 +55,7 @@ setup_file() {
5455

5556
# Configure CoCo settings in containerd config
5657
local saved_containerd_conf_file="/etc/containerd/config.toml.$$"
57-
configure_cc_containerd "${saved_containerd_conf_file}"
58+
restart_containerd
5859

5960
# KBS setup and run
6061
echo "Setting up simple-kbs..."

integration/kubernetes/confidential/snp.bats

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export SSH_KEY_FILE
2121
load "${BATS_TEST_DIRNAME}/../../confidential/lib.sh"
2222
load "${TESTS_REPO_DIR}/lib/common.bash"
2323
load "${TESTS_REPO_DIR}/integration/kubernetes/lib.sh"
24+
load "${BATS_TEST_DIRNAME}/tests_common.sh"
2425

2526
# Delete all test services
2627
k8s_delete_all() {
@@ -37,7 +38,7 @@ setup_file() {
3738

3839
# Configure CoCo settings in containerd config
3940
local saved_containerd_conf_file="/etc/containerd/config.toml.$$"
40-
configure_cc_containerd "${saved_containerd_conf_file}"
41+
restart_containerd
4142

4243
# Pull unencrypted image and retrieve ssh keys
4344
echo "Pulling unencrypted image and retrieve ssh key..."

integration/kubernetes/confidential/tests_common.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,21 @@ setup_common() {
2525
pod_id=""
2626

2727
kubernetes_delete_all_cc_pods_if_any_exists || true
28+
}
29+
30+
# Setup containerd for tests.
31+
#
32+
setup_containerd() {
33+
setup_common
2834

2935
echo "Prepare containerd for Confidential Container"
3036
SAVED_CONTAINERD_CONF_FILE="/etc/containerd/config.toml.$$"
3137
configure_cc_containerd "$SAVED_CONTAINERD_CONF_FILE"
38+
}
3239

40+
# Reconfigure Kata for tests
41+
#
42+
reconfigure_kata() {
3343
echo "Reconfigure Kata Containers"
3444
switch_image_service_offload on
3545
clear_kernel_params
@@ -58,6 +68,14 @@ teardown_common() {
5868
add_kernel_params "${original_kernel_params}"
5969
switch_image_service_offload off
6070
disable_full_debug
71+
72+
# Restore containerd to pre-test state.
73+
if [ -f "$SAVED_CONTAINERD_CONF_FILE" ]; then
74+
systemctl stop containerd || true
75+
sleep 5
76+
mv -f "$SAVED_CONTAINERD_CONF_FILE" "/etc/containerd/config.toml"
77+
systemctl start containerd || true
78+
fi
6179
}
6280

6381

@@ -97,8 +115,9 @@ create_test_pod() {
97115
new_pod_config() {
98116
local base_config="${FIXTURES_DIR}/pod-config.yaml.in"
99117
local image="$1"
118+
local index="${2:-}"
100119

101120
local new_config=$(mktemp "${BATS_FILE_TMPDIR}/$(basename ${base_config}).XXX")
102-
IMAGE="$image" RUNTIMECLASS="$RUNTIMECLASS" envsubst < "$base_config" > "$new_config"
121+
IMAGE="$image" RUNTIMECLASS="$RUNTIMECLASS" INDEX="$index" envsubst < "$base_config" > "$new_config"
103122
echo "$new_config"
104123
}

0 commit comments

Comments
 (0)