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

Commit d65cc45

Browse files
author
Chelsea Mafrica
committed
ci: add script to configure containerd for sgx
Using Kata containers in a kubernetes cluster with SGX requires a pod annotation. Add script that configures and unconfigures this annotation. Fixes #5374 Signed-off-by: Chelsea Mafrica <[email protected]>
1 parent dcbbe30 commit d65cc45

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2023 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
8+
set -o errexit
9+
set -o nounset
10+
set -o pipefail
11+
12+
cidir=$(dirname "$0")
13+
source "${cidir}/lib.sh"
14+
15+
[ "$#" -eq 1 ] || die "Specify configure or unconfigure"
16+
17+
containerd_config_file="/etc/containerd/config.toml"
18+
pod_annotations_sgx="\"sgx.intel.com\/epc\""
19+
pod_annotations_orig="\"io.katacontainers.*\""
20+
pod_annotations_match="pod_annotations \= \[$pod_annotations_orig"
21+
22+
configure_annotation() {
23+
echo "Configure pod annotations for sgx"
24+
if !(grep -q "$pod_annotations_sgx" "$containerd_config_file"); then
25+
sed -i -e 's/'$pod_annotations_orig'/'$pod_annotations_orig', '$pod_annotations_sgx'/g' $containerd_config_file
26+
systemctl restart containerd
27+
fi
28+
}
29+
30+
unconfigure_annotation() {
31+
echo "Remove pod annotations for sgx"
32+
if grep -q "$pod_annotations_sgx" "$containerd_config_file"; then
33+
sed -i -e 's/, '$pod_annotations_sgx'//g' $containerd_config_file
34+
systemctl restart containerd
35+
fi
36+
}
37+
38+
main() {
39+
cmd="$1"
40+
41+
if !(grep -q "$pod_annotations_match" "$containerd_config_file"); then
42+
die "'$containerd_config_file' is missing expected pod annotations; check that Kata is set up with kata-deploy"
43+
fi
44+
45+
case "$cmd" in
46+
configure ) configure_annotation ;;
47+
unconfigure ) unconfigure_annotation ;;
48+
*) die "invalid command: '$cmd'" ;;
49+
esac
50+
}
51+
52+
main "$@"

0 commit comments

Comments
 (0)