diff --git a/tools/packaging/kata-deploy-cc/scripts/kata-deploy.sh b/tools/packaging/kata-deploy-cc/scripts/kata-deploy.sh index ca893eb6fb..86828c652f 100755 --- a/tools/packaging/kata-deploy-cc/scripts/kata-deploy.sh +++ b/tools/packaging/kata-deploy-cc/scripts/kata-deploy.sh @@ -8,15 +8,18 @@ set -o errexit set -o pipefail set -o nounset +crio_drop_in_conf_dir="/etc/crio/crio.conf.d/" +crio_drop_in_conf_file="${crio_drop_in_conf_dir}/99-kata-deploy" containerd_conf_file="/etc/containerd/config.toml" containerd_conf_file_backup="${containerd_conf_file}.bak" shims=( - "qemu" - "qemu-tdx" - "qemu-sev" - "clh" - "clh-tdx" + "remote" + "qemu" + "qemu-tdx" + "qemu-sev" + "clh" + "clh-tdx" ) default_shim="qemu" @@ -63,6 +66,9 @@ function configure_cri_runtime() { configure_different_shims_base case $1 in + crio) + configure_crio + ;; containerd | k3s | k3s-agent | rke2-agent | rke2-server) configure_containerd ;; @@ -138,6 +144,47 @@ function cleanup_different_shims_base() { restore_shim "${default_shim_file}" } +function configure_crio_runtime() { + local runtime="kata" + local configuration="configuration" + if [ -n "${1-}" ]; then + runtime+="-$1" + configuration+="-$1" + fi + + local kata_path="/usr/local/bin/containerd-shim-${runtime}-v2" + local kata_conf="crio.runtime.runtimes.${runtime}" + local kata_config_path="/opt/confidential-containers/share/defaults/kata-containers/$configuration.toml" + + cat < "$containerd_conf_file" + if [ "$runtime" == "k3s" ] || [ "$runtime" == "k3s-agent" ] || [ "$runtime" == "rke2-agent" ] || [ "$runtime" == "rke2-server" ]; then + containerd_conf_tmpl_file="${containerd_conf_file}.tmpl" + if [ ! -f "$containerd_conf_tmpl_file" ]; then + cp "$containerd_conf_file" "$containerd_conf_tmpl_file" + fi + + containerd_conf_file="${containerd_conf_tmpl_file}" + containerd_conf_file_backup="${containerd_conf_file}.bak" + elif [ "$runtime" == "containerd" ]; then + # runtime == containerd + if [ ! -f "$containerd_conf_file" ] && [ -d $(dirname "$containerd_conf_file") ] && \ + [ -x $(command -v containerd) ]; then + containerd config default > "$containerd_conf_file" + fi + # CRI-O isn't consistent with the naming -- let's use crio to match the service file + elif [ "$runtime" == "cri-o" ]; then + runtime="crio" fi action=${1:-} @@ -260,25 +335,29 @@ function main() { die "invalid arguments" fi - case "$action" in - install) - install_artifacts - configure_cri_runtime "$runtime" - kubectl label node "$NODE_NAME" --overwrite katacontainers.io/kata-runtime=true - ;; - cleanup) - cleanup_cri_runtime "$runtime" - kubectl label node "$NODE_NAME" --overwrite katacontainers.io/kata-runtime=cleanup - remove_artifacts - ;; - reset) - reset_runtime $runtime - ;; - *) - echo invalid arguments - print_usage - ;; - esac + # only install / remove / update if we are dealing with containerd + if [[ "$runtime" =~ ^(containerd|k3s|k3s-agent|rke2-agent|rke2-server|crio)$ ]]; then + + case "$action" in + install) + install_artifacts + configure_cri_runtime "$runtime" + kubectl label node "$NODE_NAME" --overwrite katacontainers.io/kata-runtime=true + ;; + cleanup) + cleanup_cri_runtime "$runtime" + kubectl label node "$NODE_NAME" --overwrite katacontainers.io/kata-runtime=cleanup + remove_artifacts + ;; + reset) + reset_runtime $runtime + ;; + *) + echo invalid arguments + print_usage + ;; + esac + fi #It is assumed this script will be called as a daemonset. As a result, do # not return, otherwise the daemon will restart and rexecute the script