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